使用YouTubePlayerSupportFragment
只要我连接到WiFi,它就可以正常工作,但是一旦我切换到移动数据连接,在成功播放几秒钟后,片段似乎试图显示一些对话框,但是没有这样做。 / p>
以下是例外:
android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
at android.view.ViewRootImpl.setView(ViewRootImpl.java:571)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:246)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
at android.app.Dialog.show(Dialog.java:281)
at com.google.android.youtube.core.player.ar.a(SourceFile:83)
at com.google.android.youtube.core.player.Director.a(SourceFile:75)
at com.google.android.youtube.core.player.m.a(SourceFile:1205)
at com.google.android.youtube.core.async.a.f.a(SourceFile:185)
at com.google.android.youtube.core.async.k.a(SourceFile:35)
at com.google.android.youtube.core.async.ba.run(SourceFile:96)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5191)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
at dalvik.system.NativeStart.main(Native Method)
以下是片段的实例化方法:
YouTubePlayerSupportFragment youtubeFragment = YouTubePlayerSupportFragment.newInstance();
youtubeFragment.initialize(getString(R.string.id_youtube),
new YouTubePlayer.OnInitializedListener() {
@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer youTubePlayer,
boolean
b) {
mYouTubePlayer = youTubePlayer;
mYouTubePlayer.setPlayerStyle(YouTubePlayer.PlayerStyle.CHROMELESS);
next();
}
@Override
public void onInitializationFailure(YouTubePlayer.Provider provider,
YouTubeInitializationResult youTubeInitializationResult) {
getActivity().finish();
}
});
getFragmentManager().beginTransaction().add(R.id.video_wrapper, youtubeFragment).commit();
知道如何解决这个问题吗?
Goddchen