如果我投射已经在播放的视频,ExpandedControlsActivity 会消失

ExpandedControlsActivity disappears if I cast a video that is already playing

我正在使用 this project example for casting a video content on the TV screen. There are strange issues when I try to cast a video that is already playing in LocalPlayerActivity。因此,在 LocalPlayerActivity 中,我点击 play 按钮以在本地播放器中播放视频,之后,我点击 Cast 按钮和 select 设备用于投射视频内容。 ExpandedControlsActivity 应该在之后显示,出现一秒钟然后立即消失。问题是我没有触及代码中的任何内容。

这里 the video as well 为了更好地理解,有谁知道可能是什么问题?

Android日志:

I/AppCompatViewInflater: app:theme is now deprecated. Please move to using android:theme instead. D/LocalPlayerActivity: Setting url of the VideoView to: https://commondatastorage.googleapis.com/gtv-videos-bucket/CastVideos/mp4/DesigningForGoogleCast.mp4 D/LocalPlayerActivity: Controls: PlayBackState: IDLE D/LocalPlayerActivity: onStart was called D/LocalPlayerActivity: onResume() was called D/ViewRootImpl[LocalPlayerActivity]: changeCanvasOpacity: opaque=true D/ViewRootImpl[LocalPlayerActivity]: changeCanvasOpacity: opaque=false D/LocalPlayerActivity: Stopped TrickPlay Timer D/LocalPlayerActivity: Restarted TrickPlay Timer W/MediaPlayer: Couldn't open https://commondatastorage.googleapis.com/gtv-videos-bucket/CastVideos/mp4/DesigningForGoogleCast.mp4: java.io.FileNotFoundException: No content provider: https://commondatastorage.googleapis.com/gtv-videos-bucket/CastVideos/mp4/DesigningForGoogleCast.mp4 D/LocalPlayerActivity: Controls: PlayBackState: PLAYING D/MediaPlayer: getMetadata D/LocalPlayerActivity: onPrepared is reached D/LocalPlayerActivity: Stopped TrickPlay Timer D/LocalPlayerActivity: Restarted TrickPlay Timer V/MediaRouter: Dispatching route change: UserRouteInfo{ name=Nexus Player, description=Nexus Player, status=null, category=RouteCategory{ name=Devices types=ROUTE_TYPE_USER groupable=false }, supportedTypes=ROUTE_TYPE_USER , presentationDisplay=null } D/OpenGLRenderer: endAllActiveAnimators on 0x7ca1451c00 (ListView) with handle 0x7ca20e1d80 I/DynamiteModule: Considering local module com.google.android.gms.cast.framework.dynamite:0 and remote module com.google.android.gms.cast.framework.dynamite:5 I/DynamiteModule: Selected remote version of com.google.android.gms.cast.framework.dynamite, version >= 5 I/CastDynamiteModuleImpl: xv created by ClassLoader com.google.android.chimera.container.internal.DelegateLastPathClassLoader[DexPathList[[zip file "/data/data/com.google.android.gms/app_chimera/m/00000005/DynamiteModulesC_GmsCore_prodmnc_alldpi_release.apk"],nativeLibraryDirectories=[/data/user/0/com.google.android.gms/app_chimera/m/00000005/n/arm64-v8a, /system/lib64, /vendor/lib64]]]. I/DynamiteModule: Considering local module com.google.android.gms.cast.framework.dynamite:0 and remote module com.google.android.gms.cast.framework.dynamite:5 I/DynamiteModule: Selected remote version of com.google.android.gms.cast.framework.dynamite, version >= 5 I/CastDynamiteModuleImpl: xv created by ClassLoader com.google.android.chimera.container.internal.DelegateLastPathClassLoader[DexPathList[[zip file "/data/data/com.google.android.gms/app_chimera/m/00000005/DynamiteModulesC_GmsCore_prodmnc_alldpi_release.apk"],nativeLibraryDirectories=[/data/user/0/com.google.android.gms/app_chimera/m/00000005/n/arm64-v8a, /system/lib64, /vendor/lib64]]]. V/MediaRouter: Dispatching route change: UserRouteInfo{ name=Nexus Player, description=Nexus Player, status=null, category=RouteCategory{ name=Devices types=ROUTE_TYPE_USER groupable=false }, supportedTypes=ROUTE_TYPE_USER , presentationDisplay=null } D/onSessionStarted: sessionId: 5ee20da4-e9cf-4f99-ba97-bf3937df8246 D/LocalPlayerActivity: onPause() was called D/LocalPlayerActivity: Controls: PlayBackState: PAUSED I/art: Do partial code cache collection, code=122KB, data=114KB I/art: After code cache collection, code=120KB, data=113KB I/art: Increasing code cache capacity to 512KB D/LocalPlayerActivity: onResume() was called I/DynamiteModule: Considering local module com.google.android.gms.cast.framework.dynamite:0 and remote module com.google.android.gms.cast.framework.dynamite:5 I/DynamiteModule: Selected remote version of com.google.android.gms.cast.framework.dynamite, version >= 5 I/CastDynamiteModuleImpl: xv created by ClassLoader com.google.android.chimera.container.internal.DelegateLastPathClassLoader[DexPathList[[zip file "/data/data/com.google.android.gms/app_chimera/m/00000005/DynamiteModulesC_GmsCore_prodmnc_alldpi_release.apk"],nativeLibraryDirectories=[/data/user/0/com.google.android.gms/app_chimera/m/00000005/n/arm64-v8a, /system/lib64, /vendor/lib64]]]. I/DynamiteModule: Considering local module com.google.android.gms.cast.framework.dynamite:0 and remote module com.google.android.gms.cast.framework.dynamite:5 I/DynamiteModule: Selected remote version of com.google.android.gms.cast.framework.dynamite, version >= 5 I/CastDynamiteModuleImpl: xv created by ClassLoader com.google.android.chimera.container.internal.DelegateLastPathClassLoader[DexPathList[[zip file "/data/data/com.google.android.gms/app_chimera/m/00000005/DynamiteModulesC_GmsCore_prodmnc_alldpi_release.apk"],nativeLibraryDirectories=[/data/user/0/com.google.android.gms/app_chimera/m/00000005/n/arm64-v8a, /system/lib64, /vendor/lib64]]]. I/DynamiteModule: Considering local module com.google.android.gms.cast.framework.dynamite:0 and remote module com.google.android.gms.cast.framework.dynamite:5 I/DynamiteModule: Selected remote version of com.google.android.gms.cast.framework.dynamite, version >= 5 I/CastDynamiteModuleImpl: xv created by ClassLoader com.google.android.chimera.container.internal.DelegateLastPathClassLoader[DexPathList[[zip file "/data/data/com.google.android.gms/app_chimera/m/00000005/DynamiteModulesC_GmsCore_prodmnc_alldpi_release.apk"],nativeLibraryDirectories=[/data/user/0/com.google.android.gms/app_chimera/m/00000005/n/arm64-v8a, /system/lib64, /vendor/lib64]]]. V/MediaRouter: Dispatching route change: UserRouteInfo{ name=Nexus Player, description=CastVideos, status=null, category=RouteCategory{ name=Devices types=ROUTE_TYPE_USER groupable=false }, supportedTypes=ROUTE_TYPE_USER , presentationDisplay=null } V/MediaRouter: Dispatching route change: UserRouteInfo{ name=Nexus Player, description=Ready To Cast, status=null, category=RouteCategory{ name=Devices types=ROUTE_TYPE_USER groupable=false }, supportedTypes=ROUTE_TYPE_USER , presentationDisplay=null } V/MediaRouter: Dispatching route change: UserRouteInfo{ name=Kantine TV, description=Chromecast, status=null, category=RouteCategory{ name=Devices types=ROUTE_TYPE_USER groupable=false }, supportedTypes=ROUTE_TYPE_USER , presentationDisplay=null } V/MediaRouter: Dispatching route change: UserRouteInfo{ name=Kantine TV, description=Chromecast, status=null, category=RouteCategory{ name=Devices types=ROUTE_TYPE_USER groupable=false }, supportedTypes=ROUTE_TYPE_USER , presentationDisplay=null } V/MediaRouter: Dispatching route change: UserRouteInfo{ name=Nexus Player, description=Ready To Cast, status=null, category=RouteCategory{ name=Devices types=ROUTE_TYPE_USER groupable=false }, supportedTypes=ROUTE_TYPE_USER , presentationDisplay=null } I/DynamiteModule: Considering local module com.google.android.gms.cast.framework.dynamite:0 and remote module com.google.android.gms.cast.framework.dynamite:5 I/DynamiteModule: Selected remote version of com.google.android.gms.cast.framework.dynamite, version >= I/DynamiteModule: Considering local module com.google.android.gms.cast.framework.dynamite:0 and remote module com.google.android.gms.cast.framework.dynamite:5 I/DynamiteModule: Selected remote version of com.google.android.gms.cast.framework.dynamite, version >= 5 D/skia: libjpeg error 102 from read_header D/skia: --- SkAndroidCodec::NewFromStream returned null I/CastDynamiteModuleImpl: xv created by ClassLoader com.google.android.chimera.container.internal.DelegateLastPathClassLoader[DexPathList[[zip file "/data/data/com.google.android.gms/app_chimera/m/00000005/DynamiteModulesC_GmsCore_prodmnc_alldpi_release.apk"],nativeLibraryDirectories=[/data/user/0/com.google.android.gms/app_chimera/m/00000005/n/arm64-v8a, /system/lib64, /vendor/lib64]]]. I/DynamiteModule: Considering local module com.google.android.gms.cast.framework.dynamite:0 and remote module com.google.android.gms.cast.framework.dynamite:5 I/DynamiteModule: Selected remote version of com.google.android.gms.cast.framework.dynamite, version >= 5 I/CastDynamiteModuleImpl: xv created by ClassLoader com.google.android.chimera.container.internal.DelegateLastPathClassLoader[DexPathList[[zip file "/data/data/com.google.android.gms/app_chimera/m/00000005/DynamiteModulesC_GmsCore_prodmnc_alldpi_release.apk"],nativeLibraryDirectories=[/data/user/0/com.google.android.gms/app_chimera/m/00000005/n/arm64-v8a, /system/lib64, /vendor/lib64]]]. D/skia: libjpeg error 102 from read_header D/skia: --- SkAndroidCodec::NewFromStream returned null I/DynamiteModule: Considering local module com.google.android.gms.cast.framework.dynamite:0 and remote module com.google.android.gms.cast.framework.dynamite:5 I/DynamiteModule: Selected remote version of com.google.android.gms.cast.framework.dynamite, version >= 5 I/CastDynamiteModuleImpl: xv created by ClassLoader com.google.android.chimera.container.internal.DelegateLastPathClassLoader[DexPathList[[zip file "/data/data/com.google.android.gms/app_chimera/m/00000005/DynamiteModulesC_GmsCore_prodmnc_alldpi_release.apk"],nativeLibraryDirectories=[/data/user/0/com.google.android.gms/app_chimera/m/00000005/n/arm64-v8a, /system/lib64, /vendor/lib64]]]. D/skia: libjpeg error 102 from read_header D/skia: --- SkAndroidCodec::NewFromStream returned null V/MediaRouter: Dispatching route change: UserRouteInfo{ name=Nexus Player, description=Ready To Cast, status=null, category=RouteCategory{ name=Devices types=ROUTE_TYPE_USER groupable=false }, supportedTypes=ROUTE_TYPE_USER , presentationDisplay=null } V/MediaRouter: Dispatching route change: UserRouteInfo{ name=Nexus Player, description=Now Casting: Designing For Google Cast, status=null, category=RouteCategory{ name=Devices types=ROUTE_TYPE_USER groupable=false }, supportedTypes=ROUTE_TYPE_USER , presentationDisplay=null } V/MediaRouter: Dispatching route change: UserRouteInfo{ name=Kantine TV, description=Chromecast, status=null, category=RouteCategory{ name=Devices types=ROUTE_TYPE_USER groupable=false }, supportedTypes=ROUTE_TYPE_USER , presentationDisplay=null }

经过一些研究和调试,我想我找到了解决方法。在执行显示 ExpandedControlsActivity 的代码之前,我刚刚在 LocalPlayerActivity 中的方法 onStatusUpdated 中将线程停止了 500 毫秒。

remoteMediaClient.addListener(new RemoteMediaClient.Listener()
            {
                @Override
                public void onStatusUpdated()
                {
                    try
                    {
                        Thread.sleep(500); // add this line
                        Intent intent = new Intent(LocalPlayerActivity.this, ExpandedControlsActivity.class);
                        startActivity(intent);
                        remoteMediaClient.removeListener(this);
                    }
                    catch (Exception e)
                    {
                        Log.e("onStatusUpdated", e.toString());
                    }
                }
                ...

在那之后,ExpandedControlsActivity 就不再消失了。