나는 또한 webview를 사용하여 임베디드 플레이어 솔루션을 사용해 보았지만 작동하지 않습니다.
이제 Soundcloud Java API 래퍼를 사용하고 있으며 정상적으로 작동합니다. GitHub 레포의 지침에 따라 API를 구현하십시오. https://github.com/soundcloud/java-api-wrapper
코드는 매우 간단합니다. 클라이언트 ID와 클라이언트 암호 만 있으면되며, 둘 다 soundcloud 개발자 웹 사이트에서 가져와야합니다.
코드는 정말 간단하다 :
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();
}
개체 m_soundcloudPlayer
가 android.media.MediaPlayer
이다.
작동하지 않는 것과 효과가있는 것에 대해 자세히 설명해주십시오. – Cheesebaron
는 한 번만 작동했지만 노래를 전달하지 않았습니다. 아마도 이것의 더 나은 해결책 일 것입니다. – realuser