我有一个无线电应用程序,可以在谷歌Chromecast上播放实时电台。使用remotemediaplayer.load(…)启动流很好。
但是在稍后停止流时,会显示remoteMediaPlayer.requestStatus(...)并抛出一个statusCode=SIGN_IN_REQUIRED
为什么我不能停止播放实况广播?或者如何停止RemoteMediaPlayer播放?
现场无线流是http。会是问题吗?
详情如下:
以下代码启动流并使其工作。

    MediaMetadata mediaMetadata = new MediaMetadata(MediaMetadata.MEDIA_TYPE_MUSIC_TRACK);
    mediaMetadata.putString(MediaMetadata.KEY_TITLE, stationName);
    mediaMetadata.addImage(new WebImage(Uri.parse(imageUrl)));
    final MediaInfo mediaInfo = new MediaInfo.Builder(stationUrl).setContentType("audio/mp3").setStreamType(MediaInfo.STREAM_TYPE_LIVE)
            .setMetadata(mediaMetadata).build();
    try {
        mRemoteMediaPlayer.load(apiClient, mediaInfo, true).setResultCallback(new ResultCallback<RemoteMediaPlayer.MediaChannelResult>() {
            @Override
            public void onResult(MediaChannelResult result) {
                if (result.getStatus().isSuccess()) {
                    Utils.log(TAG, "Media loaded successfully: " + result.getStatus());
                } else {
                    Utils.log(TAG, "Media loaded NOT successfully: " + result.getStatus());
                }
            }
        });
    } catch .... {

以下代码将停止流,但它不起作用。
结果是IllegalStateException: No current media sessionstatusCode=SIGN_IN_REQUIRED
public static void stop() {
    try {
        mRemoteMediaPlayer.requestStatus(apiClient).setResultCallback(new ResultCallback<RemoteMediaPlayer.MediaChannelResult>() {

            @Override
            public void onResult(RemoteMediaPlayer.MediaChannelResult mediaChannelResult) {
                Status status = mediaChannelResult.getStatus();
                Utils.log(TAG, "RemoteMediaPlayer requestStatus: Status=" + status.getStatus());
                try {
                    mRemoteMediaPlayer.stop(apiClient);
                } catch (Exception e) {
                    Log.e(TAG, "Exception while stopping GoogleApiClient. ", e);
                }
            }
        });
    } catch (IllegalStateException e) {
        Log.e(TAG, "Problem occurred while geting requestStatus", e);
    } catch (Exception e) {
        Log.e(TAG, "Exception while geting requestStatus. ", e);
    }
}

日志:
05-25 06:19:58.360: D/CastHelper(30561): RemoteMediaPlayer requestStatus: Status=Status{statusCode=SIGN_IN_REQUIRED, resolution=null}
05-25 06:19:58.360: E/CastHelper(30561): Exception while stopping GoogleApiClient.
05-25 06:19:58.360: E/CastHelper(30561): java.lang.IllegalStateException: No current media session
05-25 06:19:58.360: E/CastHelper(30561):    at com.google.android.gms.internal.es.dC(Unknown Source)
05-25 06:19:58.360: E/CastHelper(30561):    at com.google.android.gms.internal.es.b(Unknown Source)
05-25 06:19:58.360: E/CastHelper(30561):    at com.google.android.gms.cast.RemoteMediaPlayer$4.a(Unknown Source)
05-25 06:19:58.360: E/CastHelper(30561):    at com.google.android.gms.cast.RemoteMediaPlayer$4.a(Unknown Source)
05-25 06:19:58.360: E/CastHelper(30561):    at com.google.android.gms.common.api.a$b.b(Unknown Source)
05-25 06:19:58.360: E/CastHelper(30561):    at com.google.android.gms.common.api.b.a(Unknown Source)
05-25 06:19:58.360: E/CastHelper(30561):    at com.google.android.gms.common.api.b.b(Unknown Source)
05-25 06:19:58.360: E/CastHelper(30561):    at com.google.android.gms.cast.RemoteMediaPlayer.stop(Unknown Source)
05-25 06:19:58.360: E/CastHelper(30561):    at com.google.android.gms.cast.RemoteMediaPlayer.stop(Unknown Source)
05-25 06:19:58.360: E/CastHelper(30561):    at com.mydomain.myapp.CastHelper$8.onResult(CastHelper.java:97)
05-25 06:19:58.360: E/CastHelper(30561):    at com.mydomain.myapp.CastHelper$8.onResult(CastHelper.java:1)
05-25 06:19:58.360: E/CastHelper(30561):    at com.google.android.gms.common.api.a$c.b(Unknown Source)
05-25 06:19:58.360: E/CastHelper(30561):    at com.google.android.gms.common.api.a$c.handleMessage(Unknown Source)
05-25 06:19:58.360: E/CastHelper(30561):    at android.os.Handler.dispatchMessage(Handler.java:102)
05-25 06:19:58.360: E/CastHelper(30561):    at android.os.Looper.loop(Looper.java:136)
05-25 06:19:58.360: E/CastHelper(30561):    at android.app.ActivityThread.main(ActivityThread.java:5579)
05-25 06:19:58.360: E/CastHelper(30561):    at java.lang.reflect.Method.invokeNative(Native Method)
05-25 06:19:58.360: E/CastHelper(30561):    at java.lang.reflect.Method.invoke(Method.java:515)
05-25 06:19:58.360: E/CastHelper(30561):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
05-25 06:19:58.360: E/CastHelper(30561):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
05-25 06:19:58.360: E/CastHelper(30561):    at dalvik.system.NativeStart.main(Native Method)

最佳答案

toString()并不是获取状态代码的好方法。RemoteMediaPlayer有自己的一组状态代码。sign_in_required是4,它是remotemediaplayer.status_replaced,这意味着您发出了与此请求类型相同的另一个请求。按设计,remotemediaplayer将只跟踪每种类型的一个请求。例如,如果在第一个暂停请求完成之前发送一个暂停,然后再发送另一个暂停(即,接收到接收器的回复),则它将停止跟踪第一个暂停并报告此错误。

10-07 12:23