问题描述
我有玩在谷歌的Chromecast直播电台的无线电应用。启动带remoteMediaPlayer.load流(...)的作品就好了。
但 remoteMediaPlayer.requestStatus(...)
供以后停止流说状态code = SIGN_IN_REQUIRED
并抛出一个 IllegalStateException异常:没有当前媒体会话
为什么我不能停止播放电台直播流?或者我怎么可以停止播放remoteMediaPlayer?
在电台直播流是HTTP。它可以是问题吗?
下面的细节:
以下code开头流和它的作品。
MediaMetadata mediaMetadata =新MediaMetadata(MediaMetadata.MEDIA_TYPE_MUSIC_TRACK);
mediaMetadata.putString(MediaMetadata.KEY_TITLE,工作站名称);
mediaMetadata.addImage(新WebImage(Uri.parse(图片网址)));
最后MediaInfo mediaInfo =新MediaInfo.Builder(stationUrl).setContentType(音频/ MP3)。setStreamType(MediaInfo.STREAM_TYPE_LIVE)
.setMetadata(mediaMetadata).build();
尝试{
mRemoteMediaPlayer.load(apiClient,mediaInfo,真).setResultCallback(新ResultCallback< RemoteMediaPlayer.MediaChannelResult>(){
@覆盖
公共无效onResult(MediaChannelResult结果){
如果(result.getStatus()。isSuccess()){
Utils.log(TAG,媒体加载成功:+ result.getStatus());
}其他{
Utils.log(TAG,媒体加载没有成功:+ result.getStatus());
}
}
});
}赶上{....
以下code停止流,并将它不起作用。
没有当前媒体会话
java.lang.IllegalStateException > 公共静态无效停止(){
尝试{
mRemoteMediaPlayer.requestStatus(apiClient).setResultCallback(新ResultCallback< RemoteMediaPlayer.MediaChannelResult>(){ @覆盖
公共无效onResult(RemoteMediaPlayer.MediaChannelResult mediaChannelResult){
状态状态= mediaChannelResult.getStatus();
Utils.log(TAG,RemoteMediaPlayer requestStatus:状态=+ status.getStatus());
尝试{
mRemoteMediaPlayer.stop(apiClient);
}赶上(例外五){
Log.e(TAG,异常而停止GoogleApiClient,E);
}
}
});
}赶上(IllegalStateException异常五){
Log.e(TAG,E,而歌厅requestStatus发生问题);
}赶上(例外五){
Log.e(TAG,异常而歌厅requestStatus,E);
}
}
LogCat中:
六月五日至25日:19:58.360:D / CastHelper(30561):RemoteMediaPlayer requestStatus:状态= {状态状态code = SIGN_IN_REQUIRED,分辨率= NULL}
6月5日至25日:19:58.360:E / CastHelper(30561):异常而停止GoogleApiClient。
6月5日至25日:19:58.360:E / CastHelper(30561):java.lang.IllegalStateException:没有当前媒体会话
6月5日至25日:19:58.360:E / CastHelper(30561):在com.google.android.gms.internal.es.dC(来源不明)
6月5日至25日:19:58.360:E / CastHelper(30561):在com.google.android.gms.internal.es.b(来源不明)
6月5日至25日:19:58.360:E / CastHelper(30561):在com.google.android.gms.cast.RemoteMediaPlayer $ 4.A(来源不明)
6月5日至25日:19:58.360:E / CastHelper(30561):在com.google.android.gms.cast.RemoteMediaPlayer $ 4.A(来源不明)
6月5日至25日:19:58.360:E / CastHelper(30561):在com.google.android.gms.common.api.a $ b.b(来源不明)
6月5日至25日:19:58.360:E / CastHelper(30561):在com.google.android.gms.common.api.b.a(来源不明)
6月5日至25日:19:58.360:E / CastHelper(30561):在com.google.android.gms.common.api.b.b(来源不明)
6月5日至25日:19:58.360:E / CastHelper(30561):在com.google.android.gms.cast.RemoteMediaPlayer.stop(来源不明)
6月5日至25日:19:58.360:E / CastHelper(30561):在com.google.android.gms.cast.RemoteMediaPlayer.stop(来源不明)
6月5日至25日:19:58.360:E / CastHelper(30561):在com.mydomain.myapp.CastHelper $ 8.onResult(CastHelper.java:97)
6月5日至25日:19:58.360:E / CastHelper(30561):在com.mydomain.myapp.CastHelper $ 8.onResult(CastHelper.java:1)
6月5日至25日:19:58.360:E / CastHelper(30561):在com.google.android.gms.common.api.a $ C.B(来源不明)
6月5日至25日:19:58.360:E / CastHelper(30561):在com.google.android.gms.common.api.a $ c.handleMessage(来源不明)
6月5日至25日:19:58.360:E / CastHelper(30561):在android.os.Handler.dispatchMessage(Handler.java:102)
6月5日至25日:19:58.360:E / CastHelper(30561):在android.os.Looper.loop(Looper.java:136)
6月5日至25日:19:58.360:E / CastHelper(30561):在android.app.ActivityThread.main(ActivityThread.java:5579)
6月5日至25日:19:58.360:E / CastHelper(30561):在java.lang.reflect.Method.invokeNative(本机方法)
6月5日至25日:19:58.360:E / CastHelper(30561):在java.lang.reflect.Method.invoke(Method.java:515)
6月5日至25日:19:58.360:E / CastHelper(30561):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1268)
6月5日至25日:19:58.360:E / CastHelper(30561):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
6月5日至25日:19:58.360:E / CastHelper(30561):在dalvik.system.NativeStart.main(本机方法)
解决方案 的toString()是不是真的要获得状态code的好办法。 RemoteMediaPlayer有自己的一套STATUS_ * codeS的。 SIGN_IN_REQUIRED是4,这是RemoteMediaPlayer.STATUS_REPLACED这意味着你发出的相同类型此请求的另一个请求。的RemoteMediaPlayer,通过设计,将仅跟踪每个类型的一个请求。例如,如果你发送一个暂停之后又暂停了第一个暂停请求完成之前(即收到了接收器的回复),它将停止跟踪第一个暂停,并报告该错误。
I have a radio application which plays live radio stations on Google Chromecast. Starting a stream with remoteMediaPlayer.load(...) works just fine.But remoteMediaPlayer.requestStatus(...)
for later stopping the stream says statusCode=SIGN_IN_REQUIRED
and throws a IllegalStateException: No current media session
Why can't I stop the playing live radio stream? Or how can I stop the remoteMediaPlayer playback?
The live radio streams are HTTP. Can it be the problem?
Here the details:
The following code starts the stream and it works.
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 .... {
The following code stops the stream and it does not work.The result ist statusCode=SIGN_IN_REQUIRED
and java.lang.IllegalStateException: No current media session
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);
}
}
LogCat:
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() isn't really a good way to get the status code. RemoteMediaPlayer has its own set of STATUS_* codes. SIGN_IN_REQUIRED is 4, which is RemoteMediaPlayer.STATUS_REPLACED which means that you issued another request of the same type as this request. The RemoteMediaPlayer, by design, will only track one request of each type. For example, if you send a PAUSE followed by another PAUSE before the first PAUSE request has completed (i.e., received a reply from the receiver), it will stop tracking the first PAUSE and report this error.
这篇关于remoteMediaPlayer.requestStatus(...)返回状态code SIGN_IN_REQUIRED的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!