api - How to embed the SoundCloud player in Android? -


i want embed soundcloud player play soundcloud url in android app.

i had tried use soundcloud java api wrapper. thing giving me error when try track:

this line causes error

 httpresponse trackresp = wrapper.get(request.to("/tracks/60913196")); 

error - 13781-13781/ com.example.dds.soundcloud e/trace﹕ error opening trace file: no such file or directory (2)

if having working project of soundcloud player in android app. request please share project.

this present code.

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 user-specific actions;     //wrapper.login("<user>", "<pass>");     //httpresponse resp = wrapper.get(request.to("/me"));     //get 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 streamable, fetch stream url (mp3-https) , start 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(); } 

you can play html5 player of soundcloud in webview, need following.

//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 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 , (-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 , height want 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", ""); 

Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -