2
我想嵌入SoundCloud播放器在我的Android應用程序中播放SoundCloud URL。如何在Android中嵌入SoundCloud播放器?
我曾嘗試使用SoundCloud Java API封裝。但是,這件事是給我一個錯誤,當我試圖讓曲目:
此行導致錯誤
HttpResponse trackResp = wrapper.get(Request.to("/tracks/60913196"));
錯誤 - 13781-13781/com.example.DDS.soundcloud E /跟蹤:錯誤打開 跟蹤文件:沒有這樣的文件或目錄(2)
如果有人爲的SoundCloud播放器的Android應用中的工作項目。我請求你請分享這個項目。
這是我現在的代碼。
String id = getResources().getString(R.string.sc_client_id);
String secret = getResources().getString(R.string.sc_client_secret);
ApiWrapper wrapper = new ApiWrapper(id,secret, null, null);
try {
//Only needed for user-specific actions;
//wrapper.login("<user>", "<pass>");
//HttpResponse resp = wrapper.get(Request.to("/me"));
//Get a track
HttpResponse trackResp = wrapper.get(Request.to("/tracks/60913196"));
//Track JSON response OK?
if(trackResp.getStatusLine().getStatusCode() == HttpStatus.SC_OK)
{
JSONObject trackJSON = new JSONObject(EntityUtils.toString(trackResp.getEntity()));
//If track is streamable, fetch the stream URL (mp3-https) and start the MediaPlayer
if(trackJSON.getBoolean("streamable"))
{
HttpResponse streamResp = wrapper.get(Request.to("/tracks/60913196/stream"));
JSONObject streamJSON = new JSONObject(EntityUtils.toString(streamResp.getEntity()));
String streamurl = streamJSON.getString("location");
Log.i("SoundCloud", trackJSON.getString("streamable"));
Log.i("SoundCloud", streamurl);
m_soundcloudPlayer.stop();
m_soundcloudPlayer = new MediaPlayer();
m_soundcloudPlayer.setDataSource(streamurl);
m_soundcloudPlayer.prepare();
m_soundcloudPlayer.start();
}
}
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}catch (ParseException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (JSONException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
難道你還可以添加一個解釋? – Robert
我已經添加了一個解釋。 –
謝謝...... =) – Robert