-2

我希望我的媒体播放器(android)应该从这个 url 播放歌曲。我每天使用 JSON 文件更新我的播放列表文件。请帮助我,我被困住了,谢谢。

{
    "json": {
        "Songs": [
            {
                "song": "Song name ",
                "Artist": "Sonjay singh",
                "mp3": "http://c2lo.reverbnation.com/audio_player/download_song_direct/9140921.mp3"
            },
            {
                "song": "SONG NAME",
                "Artist": "aritist",
                "mp3": "mp3_URL"
            },
            {
                "song": "SONG NAME",
                "Artist": "aritist",
                "mp3": "mp3_URL"
            }
        ]
    }
}

我做了这门课,但仍然很难使用它。谢谢你的帮助。

public class Json{
private List songs;

public List getSongs(){
    return this.songs;
}
public void setSongs(List songs){
    this.songs = songs;
}
 }

//

    public class Songs{
private String artist;
private String mp3;
private String song;

public String getArtist(){
    return this.artist;
}
public void setArtist(String artist){
    this.artist = artist;
}
public String getMp3(){
    return this.mp3;
}
public void setMp3(String mp3){
    this.mp3 = mp3;
}
public String getSong(){
    return this.song;
}
public void setSong(String song){
    this.song = song;
}
    }

//

public class SongsDataBase{
private Json json;

public Json getJson(){
    return this.json;
}
public void setJson(Json json){
    this.json = json;
}
 }
4

3 回答 3

1

使用Google gson解析它- 将 url 加载到您的媒体播放器中,完成工作。

于 2013-05-14T11:54:13.260 回答
0

使用 Gson。这很简单,创建一个具有相同变量名(歌曲、艺术家、...)的类(比如 classB),然后使用 classB 变量列表创建另一个类(比如 classC),然后分配它

Gson gson = new Gson();

阅读器 r = new InputStreamReader(strJson(url));

classC C = gson.fromJson(r, ClassC.class);

于 2013-05-14T12:06:34.930 回答
0
Use this way to play audio songs

public class StreamAudioDemo extends Activity implements OnClickListener, OnPreparedListener, OnCompletionListener, OnErrorListener{

    private MediaPlayer mp;
    private ProgressDialog pd;
    private Button btnplay;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        btnplay=(Button)findViewById(R.id.play);
        btnplay.setOnClickListener(this);
    }
    @Override
    public void onPrepared(MediaPlayer mp) {
          Log.i("StreamAudioDemo", "prepare finished");
          pd.setMessage("Playing.....");
          mp.start();
    }

    @Override
    public void onClick(View v) {
        try
        {
            pd = new ProgressDialog(this);
            pd.setMessage("Buffering.....");
            pd.show();
            mp = new MediaPlayer();
            mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
            mp.setOnPreparedListener(this);
            mp.setOnErrorListener(this);  //http://www.youtube.com/watch?v=pj-T_LxSCng
            mp.setDataSource("http://c2lo.reverbnation.com/audio_player/download_song_direct/9140921.mp3");

            mp.prepareAsync();
            mp.setOnCompletionListener(this);
        }
        catch(Exception e)
        {
            Log.e("StreamAudioDemo", e.getMessage());
        }

    }

    @Override
    public void onCompletion(MediaPlayer arg0) {
        pd.dismiss();
        Toast.makeText(getApplicationContext(), "Completed", Toast.LENGTH_LONG).show();     

    }
    @Override
    public boolean onError(MediaPlayer mp, int what, int extra) {
        // TODO Auto-generated method stub
        pd.dismiss();
        return false;
    }

}
于 2013-05-14T11:55:25.627 回答