2
votes

I been trying to stream some tracks in a mobile app I built in phonegap but the SC.stream() function of sound cloud returns nothing on mobile but works in a desktop browser. Also the SC.get works, but the problem is when I try to stream.

This is the code:

    /* this works */
    SC.initialize({
        client_id: '76e637279c08c0a0e1ed081e22f0d37e'
    });

    SC.get("https://api.soundcloud.com/users/185201/tracks", {limit: 6 }, function(tracks){
     /* ...   */
    });

    /* This doesn */
    function playPauseTrack( souncloundTrackId, $musicBlock ){
        SC.stream("http://api.soundcloud.com/tracks/"+souncloundTrackId, function(track){

            $musicBlock.click( function(){
                    //...
                    //...

            });

        });
    }
3

3 Answers

0
votes

On mobile devices user action is required to trigger playback – so calls to stream have to be inside of a call stack of a user action such as click.

0
votes

You need to modify the app file for your project. Navigate to your cordova project under: platforms/android/src/com/whatever/myProject. Then add the following highlighted lines to your file:

package com.example.myProject;

import android.os.Bundle;
import org.apache.cordova.*;
import android.webkit.WebSettings;

public class myProject extends CordovaActivity 
{
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        super.init();
        // Set by <content src="index.html" /> in config.xml
        super.loadUrl(Config.getStartUrl());
        //super.loadUrl("file:///android_asset/www/index.html");

        WebSettings ws = super.appView.getSettings();
        ws.setMediaPlaybackRequiresUserGesture(false);
    }
}
0
votes

Attach a promise:

SC.stream(url).then(function(player){
   var track = player;       
   // track.play();
   // track.pause(); ....      
});