我目前正在使用VideoView播放rtsp直播流媒體源。這工作正常。Android VideoView:從父視圖中刪除後視頻變黑
VideoView最初是在其他元素的片段內,處於'正常'狀態,並且我試圖實現一個全屏切換按鈕。 。
要進入全屏模式,我從它的父(一LinearLayout中)取出VideoView,然後將它添加到另一個LinearLayout中,添加上)一切使用getActivity()addContentView(頂部,下面的代碼:
LayoutInflater lf = getActivity().getLayoutInflater();
vFullScreen = lf.inflate(R.layout.full_screen, myViewGroup, false);
LinearLayout fullscreenCont = (LinearLayout) vFullScreen.findViewById(R.id.fullscreen_container);
((ViewGroup) vsPlayer.getParent()).removeView(vsPlayer);
fullscreenCont.addView(vsPlayer);
LayoutParams params = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
getActivity().addContentView(vFullScreen, params);
的問題是,一旦它從原來的父視圖中移除視頻變黑。
我試圖實現它是保留視頻實例,以避免重新連接/緩衝區,但我不知道如何保留視頻播放在父母的切換,任何想法?
編輯:
如果我暫停videoView,然後恢復它,像這樣:
LayoutInflater lf = getActivity().getLayoutInflater();
vFullScreen = lf.inflate(R.layout.full_screen, myViewGroup, false);
LinearLayout fullscreenCont = (LinearLayout) vFullScreen.findViewById(R.id.fullscreen_container);
vsPlayer.getVideoView().suspend();
((ViewGroup) vsPlayer.getParent()).removeView(vsPlayer);
fullscreenCont.addView(vsPlayer);
LayoutParams params = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
getActivity().addContentView(vFullScreen, params);
vsPlayer.getVideoView().resume();
視頻播放中斷(變黑幾引人注目秒),但隨後恢復,至極是好得多,不完美,因爲恢復比賽需要很長時間。
另一個不那麼很大一部分是這些方法suspend()和類VideoView的簡歷()可從API級別8個,最多的,我需要與API級別7
您是否找到解決方案?我也有同樣的問題。 –