4

次のように Android アプリでサウンドクラウドを使用したい: URL アドレスを使用してサウンドクラウド プレーヤーで曲を再生したい。webview で次のコードを使用しましたが、正しく実行されませんでした。これどうやってするの?ありがとう。

<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>
4

4 に答える 4

5

代わりに、 SoundCloud の公式 Java ラッパーを使用することを検討しましたか?

于 2012-03-22T15:00:50.013 に答える
2

WebView を使用して埋め込みプレーヤー ソリューションも試しましたが、うまくいきません。

現在、Soundcloud Java API Wrapper を使用していますが、これは正常に動作します。GitHub リポジトリの指示に従って API を実装します: https://github.com/soundcloud/java-api-wrapper

コードは非常に簡単です。クライアント ID とクライアント シークレットのみが必要です。両方とも、soundcloud 開発者の Web サイトで取得する必要があります。

コードは非常に簡単です。

        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.

于 2014-02-12T10:09:53.350 に答える
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", "");
于 2015-12-11T14:24:47.113 に答える
1

私は同じ問題を抱えています。標準の埋め込みコードが機能しない理由は、Android ブラウザーが HTML5 オーディオ コーデックをサポートしていないことが原因であることがわかりました。最良のショットは、私が推測する公式のラッパーですが、これを行う方法はまだわかりません (単なるアマチュア)。

于 2012-05-31T11:48:14.027 に答える