大家好,
我的应用程序运行正常,我看到来自youtube的视频但是当我改变方向时,我一直看到视频,但是日志给了我泄漏ServiceConnection的错误。
public class PlayerYouTubeFrag extends YouTubePlayerSupportFragment {
public PlayerYouTubeFrag() {
// TODO Auto-generated constructor stub
}
private String currentVideoID = "wKJ9KzGQq0w";
private YouTubePlayer activePlayer;
private int section_id;
private Realm realm;
public static PlayerYouTubeFrag newInstance(int section_id) {
PlayerYouTubeFrag playerYouTubeFrag = new PlayerYouTubeFrag();
Bundle bundle = new Bundle();
bundle.putInt("section_id", section_id);
playerYouTubeFrag.setArguments(bundle);
return playerYouTubeFrag;
}
private void init() {
initialize(Constants.DEVELOPER_KEY, new OnInitializedListener() {
@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer player, boolean wasRestored) {
player.setFullscreenControlFlags(0);
if (!wasRestored) {
activePlayer = player;
//activePlayer.setFullscreen(true);
activePlayer.loadVideo("2zNSgSzhBfM");
activePlayer.play();
}
}
@Override
public void onInitializationFailure(Provider arg0,
YouTubeInitializationResult arg1) {
Log.i("YouTube faillure", "Provider "+arg0.toString()+" YouTubeInitializationResult "+arg1.ordinal());
// TODO Auto-generated method stub
}
});
}
@Override
public View onCreateView(LayoutInflater arg0, ViewGroup arg1, Bundle arg2) {
init();
return super.onCreateView(arg0, arg1, arg2);
}
@Override
public void onPause() {
super.onPause();
activePlayer.release();
}
@Override
public void onAttach(Activity activity) {
realm = Realm.getInstance(getActivity());
if (getArguments() != null) {
section_id = getArguments().getInt("section_id");
Section section = realm.where(Section.class).equalTo("id_s",section_id).findFirst();
// appController.getSectionsDao().queryForId(section_id);
if (section.getType().equalsIgnoreCase("video")) {
String pattern = "(?<=watch\\?v=|v\\/|/videos/|embed\\/)[^#\\&\\?]*"; // "(?<=watch\\?v=|/videos/|embed\\/)[^#\\&\\?]*" // "\b(?<=v.|/)[a-zA-Z0-9_-]{11,}\b"
Pattern compiledPattern = Pattern.compile(pattern);
Matcher matcher = compiledPattern.matcher(section.getRoot_url());
if(matcher.find())
{
currentVideoID = matcher.group();
}
}
}
((MainActivity) getActivity()).extras = getArguments();
super.onAttach(activity);
}
}
活动com.euphor.paperpad.activities.main.MainActivity已泄露 ServiceConnection com.google.android.youtube.player.internal.r$e@2bc2136c那是 最初绑在这里 android.app.ServiceConnectionLeaked:Activity com.euphor.paperpad.activities.main.MainActivity泄露了 ServiceConnection com.google.android.youtube.player.internal.r$e@2bc2136c那是 最初绑在这里 在android.app.LoadedApk $ ServiceDispatcher。(LoadedApk.java:1077) 在android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:971) 在android.app.ContextImpl.bindServiceCommon(ContextImpl.java:1782) 在android.app.ContextImpl.bindService(ContextImpl.java:1765) 在android.content.ContextWrapper.bindService(ContextWrapper.java:539) 在com.google.android.youtube.player.internal.r.e(未知来源) 在com.google.android.youtube.player.YouTubePlayerView.a(未知 资源) 在 com.google.android.youtube.player.YouTubePlayerSupportFragment.a(未知 资源) 在 com.google.android.youtube.player.YouTubePlayerSupportFragment.onCreateView(未知 资源) 在 com.euphor.paperpad.activities.fragments.PlayerYouTubeFrag.onCreateView(PlayerYouTubeFrag.java:105) 在 android.support.v4.app.Fragment.performCreateView(Fragment.java:1460) 在 android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:911) 在 android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1088) 在 android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1070) 在 android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:1861) 在 android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:547) 在 android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1236) 在android.app.Activity.performStart(Activity.java:6006) 在 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2288) 在 android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) 在 android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3947) 在android.app.ActivityThread.access $ 900(ActivityThread.java:151) 在 android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1309) 在android.os.Handler.dispatchMessage(Handler.java:102) 在android.os.Looper.loop(Looper.java:135) 在android.app.ActivityThread.main(ActivityThread.java:5254) at java.lang.reflect.Method.invoke(Native Method) 在java.lang.reflect.Method.invoke(Method.java:372) 在 com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:903) 在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
在发布我的问题之前,我找到了一个解决方案,我找到的内容对我不起作用,我在onPause中添加了这个版本但没有结果。
感谢&#39; S