Changed buffering to be asynchronous.
This commit is contained in:
parent
598522701e
commit
ca0439bf8f
2 changed files with 16 additions and 16 deletions
|
@ -14,7 +14,7 @@ import android.support.v7.media.MediaRouteProvider;
|
|||
import android.support.v7.media.MediaRouter.ControlRequestCallback;
|
||||
|
||||
public class Controller extends MediaRouteProvider.RouteController implements
|
||||
MediaPlayer.OnCompletionListener {
|
||||
MediaPlayer.OnCompletionListener, MediaPlayer.OnPreparedListener {
|
||||
|
||||
private Context mContext;
|
||||
|
||||
|
@ -28,13 +28,14 @@ public class Controller extends MediaRouteProvider.RouteController implements
|
|||
|
||||
private int mState;
|
||||
|
||||
MediaPlayer mPlayer = new MediaPlayer();
|
||||
private MediaPlayer mPlayer = new MediaPlayer();
|
||||
|
||||
public Controller(String routeId, Context context) {
|
||||
mContext = context;
|
||||
mRouteId = routeId;
|
||||
mAudio = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
|
||||
mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
|
||||
mPlayer.setOnPreparedListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -72,11 +73,10 @@ public class Controller extends MediaRouteProvider.RouteController implements
|
|||
try {
|
||||
mPlayer.reset();
|
||||
mPlayer.setDataSource(mContext, intent.getData());
|
||||
mPlayer.prepare();
|
||||
mPlayer.start();
|
||||
mPlayer.prepareAsync();
|
||||
mItemId = intent.getDataString();
|
||||
mState = MediaItemStatus.PLAYBACK_STATE_PLAYING;
|
||||
getStatus(mItemId, mRouteId, callback);
|
||||
mState = MediaItemStatus.PLAYBACK_STATE_BUFFERING;
|
||||
getStatus(mItemId, mRouteId, callback);
|
||||
return true;
|
||||
} catch (IllegalArgumentException e) {
|
||||
mState = MediaItemStatus.PLAYBACK_STATE_ERROR;
|
||||
|
@ -135,11 +135,16 @@ public class Controller extends MediaRouteProvider.RouteController implements
|
|||
.build().asBundle();
|
||||
|
||||
callback.onResult(status);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCompletion(MediaPlayer mp) {
|
||||
mState = MediaItemStatus.PLAYBACK_STATE_FINISHED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPrepared(MediaPlayer mp) {
|
||||
mPlayer.start();
|
||||
mState = MediaItemStatus.PLAYBACK_STATE_PLAYING;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,11 +13,6 @@ import android.support.v7.media.MediaRouteProvider;
|
|||
import android.support.v7.media.MediaRouteProviderDescriptor;
|
||||
import android.support.v7.media.MediaRouter;
|
||||
|
||||
/**
|
||||
* Demonstrates how to create a custom media route provider.
|
||||
*
|
||||
* @see SampleMediaRouteProviderService
|
||||
*/
|
||||
final class Provider extends MediaRouteProvider {
|
||||
|
||||
private static final String ROUTE_ID = "local_route";
|
||||
|
|
Reference in a new issue