2012-01-05 3 views
4

내 안드로이드 앱에서 soundcloud를 사용하고 싶습니다. url 주소가있는 soundcloud 플레이어에서 노래를 재생하고 싶습니다. webview에서 다음 코드를 사용했지만 제대로 실행되지 않았습니다. 어떻게해야합니까? 감사합니다. .내 안드로이드 앱에서 SoundCloud를 사용하려면 어떻게해야합니까?

<iframe width=\"100%\" height=\"166\" scrolling=\"no\" frameborder=\"no\" src=\"http://w.soundcloud.com/player/?url=http%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F31416027&amp;auto_play=false&amp;show_artwork=false&amp;color=ff7700\"></iframe> 
+0

작동하지 않는 것과 효과가있는 것에 대해 자세히 설명해주십시오. – Cheesebaron

+0

는 한 번만 작동했지만 노래를 전달하지 않았습니다. 아마도 이것의 더 나은 해결책 일 것입니다. – realuser

답변

1

동일한 문제가 있습니다. 표준 삽입 코드가 작동하지 않는 이유는 HTML5 오디오 코덱을 지원하지 않는 Android 브라우저 때문입니다. 가장 좋은 기회는 내가 생각하기에 공식적인 래퍼이지만, 아직 어떻게하는지 (아마추어 만)는 잘 모르겠습니다.

+0

souldcloud java-wrapper-api https://github.com/soundcloud/java-api-wrapper 라이브러리를 내 Android 앱에 가져 오는 방법은 무엇입니까? –

2

나는 또한 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_soundcloudPlayerandroid.media.MediaPlayer이다.

0

SoundCloud Java Api Wrapper를 사용해 보았습니다. 하지만 그 일로 트랙을 얻으 려 할 때 오류가 발생합니다. 오류 개방 추적 파일 : 해당 파일이나 디렉토리 (2)

13781-13781/com.example.DDS.soundcloud E/추적 - 라인

HttpResponse trackResp = wrapper.get(Request.to("/tracks/60913196")); 

오류에있다

안드로이드 앱에서 Soundcloud 플레이어의 작업 프로젝트를 진행중인 사람이있는 경우. 우리와 함께 프로젝트를 공유해 주시기 바랍니다.

1
//In Activity_layout.xml 

<LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:orientation="vertical"> 
     <WebView android:id="@+id/webview" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        /> 

    </LinearLayout> 



// In ActivityClass.java 

    mSoundCloudPlayer =(WebView) findViewById(R.id.webview); 

    String VIDEO_URL = "Set Your Embedded URL"; 

    String html = "<!DOCTYPE html><html> <head> <meta charset=\"UTF-8\"><meta name=\"viewport\" content=\"target-densitydpi=high-dpi\" /> <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"> <link rel=\"stylesheet\" media=\"screen and (-webkit-device-pixel-ratio:1.5)\" href=\"hdpi.css\" /></head> <body style=\"background:black;margin:0 0 0 0; padding:0 0 0 0;\"> <iframe id=\"sc-widget " + 
            "\" width=\"100%\" height=\"50%\"" + // Set Appropriate Width and Height that you want for SoundCloud Player 
            " src=\"" + VIDEO_URL // Set Embedded url 
            + "\" frameborder=\"no\" scrolling=\"no\"></iframe>" + 
            "<script src=\"https://w.soundcloud.com/player/api.js\" type=\"text/javascript\"></script> </body> </html> "; 

      mSoundCloudPlayer.setVisibility(View.VISIBLE); 
      mSoundCloudPlayer.getSettings().setJavaScriptEnabled(true); 
      mSoundCloudPlayer.getSettings().setLoadWithOverviewMode(true); 
      mSoundCloudPlayer.getSettings().setUseWideViewPort(true); 
      mSoundCloudPlayer.loadDataWithBaseURL("",html,"text/html", "UTF-8", ""); 
관련 문제