JSON不能以正确的顺序解析轨道 [英] JSON not parsing tracks in correct order

查看:53
本文介绍了JSON不能以正确的顺序解析轨道的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个JSON文件,我的Android应用将其列表中的内容放入赞歌中,并按特定的顺序放入赞美诗中.以前,我的所有文件都保存在copticchurch-library.org/media中.这包括所有媒体和JSON文件本身.但是,我想做更多的组织工作,因为添加更多媒体时可能会变得有些混乱.

I created a JSON file of which my Android app pulls the list and puts the hymn and puts them in a specific order. Previously, I had all my files in copticchurch-library.org/media. This included all the media and the JSON file itself. However, I would like to do more organization seeing as it might get a little disorganized when adding more media.

我在copticchurch-library.org/media/matinsandvespers中创建了一个新目录. 此目录包含与该文件夹有关的所有媒体(mp3和专辑封面). JSON文件夹仍在copticchurch-library.org/media

I created a new directory at copticchurch-library.org/media/matinsandvespers. This directory has all the media (mp3 and album art) pertaining to that folder. The JSON folder is still in copticchurch-library.org/media

问题 为什么它没有在应用程序中以正确的顺序列出曲目?

Issue Why is it that it does not list the tracks in the correct order on the app?

JSON代码

{"music" : [ 
{ "title" : "Mercy and Compassion",
  "album" : "Standard Deacon Responses",
  "artist" : "Cantor Ibrahim Ayad",
  "genre" : "Standard Deacon Responses",
  "source" : "http://copticchurch-library.org/media/matinsandvespers/Mercy_compassion.mp3",
  "image" : "http://copticchurch-library.org/media/matinsandvespers/image1.jpg",
  "trackNumber" : 1,
  "totalTrackCount" : 5,
  "duration" : 57,
  "site" : "http://copticchurch-library.org/media/matinsandvespers"
},
{ "title" : "Litany of the Departed",
  "album" : "Standard Deacon Responses",
  "artist" : "Cantor Ibrahim Ayad",
  "genre" : "Standard Deacon Responses",
  "source" : "http://copticchurch-library.org/media/matinsandvespers/Litany_departed.mp3",
  "image" : "http://copticchurch-library.org/media/matinsandvespers/image2.jpg",
  "trackNumber" : 2,
  "totalTrackCount" : 5,
  "duration" : 95,
  "site" : "http://copticchurch-library.org/media/matinsandvespers"
},
{ "title" : "Litany of the Sick",
  "album" : "Standard Deacon Responses",
  "artist" : "Cantor Ibrahim Ayad",
  "genre" : "Standard Deacon Responses",
  "source" : "http://copticchurch-library.org/media/matinsandvespers/Litany_sick.mp3",
  "image" : "http://copticchurch-library.org/media/matinsandvespers/image3.jpg",
  "trackNumber" : 3,
  "totalTrackCount" : 5,
  "duration" : 43,
  "site" : "http://copticchurch-library.org/media/matinsandvespers"
},
    { "title" : "Litany of the Travelers",
  "album" : "Standard Deacon Responses",
  "artist" : "Cantor Ibrahim Ayad",
  "genre" : "Standard Deacon Responses",
  "source" : "http://copticchurch-library.org/media/matinsandvespers/Litany_travlers.mp3",
  "image" : "http://copticchurch-library.org/media/matinsandvespers/image4.jpg",
  "trackNumber" : 4,
  "totalTrackCount" : 5,
  "duration" : 61,
  "site" : "http://copticchurch-library.org/media/matinsandvespers"
},

根据代码和屏幕截图,一切都乱了,我不知道为什么.

Based on the code and the screenshot, everything is out of order and I can't figure out why.

奇怪的是,当我将所有内容放在一个地方时它可以工作,但是当我想创建子目录时,它会失去其顺序.

Strangely it works when I put everything in one place but when I want to create sub-dir, it looses its order.

我尝试将music.json文件放在该目录中,但还是没有运气.

I've tried putting the music.json file in that directory but still no luck.

任何帮助将不胜感激.

Any help would be appreciated.

修改 我已将更多轨道添加到还原的方法中,但这些轨道仍然不正常.

Edit I've added more tracks to the reverted method and the tracks are still out of order.

编辑2

RemoteJSON.java

MusicProvider.java

编辑3 Github项目仓库

Edit 3 Github project repo

推荐答案

一个朋友帮我弄清楚该怎么做.这是他所写的代码,最终起作用了.

A friend helped me figure out how to do it. This is the code that he wrote which ended up working.

} for (String key : newMusicListByGenre.keySet())
        {
            Collections.sort(newMusicListByGenre.get(key), new Comparator<MediaMetadataCompat>() {
                @Override
                public int compare(MediaMetadataCompat track1, MediaMetadataCompat track2) {
                    return track1.getLong(MediaMetadataCompat.METADATA_KEY_TRACK_NUMBER) < track2.getLong(MediaMetadataCompat.METADATA_KEY_TRACK_NUMBER) ? -1 : 1;
                }
            });
        }
        mMusicListByGenre = newMusicListByGenre;


        list.add(m.metadata);
    }
    mMusicListByGenre = newMusicListByGenre;

}

这篇关于JSON不能以正确的顺序解析轨道的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆