gpt4 book ai didi

android - VideoView 不显示在 fragment 上

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:47:02 26 4
gpt4 key购买 nike

我在三星 S3(Android 4.1.1)中运行视频时遇到问题,问题似乎是因为 videoview 在 fragment 上,因为如果我打开它并进行 Activity ,它就可以工作。我还发现,如果我打开 GPU 硬件加速,视频就可以播放。我还有一个通过在 SurfaceView 上绘图制作的游戏,但该 View 效果不佳(仅在 GPU 开启时)...应用程序的其余内容按预期显示(按钮和其他布局)。

我在 Nexus S 和模拟器上测试了该应用程序,它运行良好,在其他设备上也是如此..

有人知道问题出在哪里吗?谢谢!

代码如下:

public class VideoFragment extends Fragment implements MediaPlayer.OnCompletionListener,
MediaPlayer.OnPreparedListener, MediaPlayer.OnErrorListener {

private Video mVideo;
private VideoView mVideoView;
// The video position
private int mPosition;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

View fragmentView = inflater.inflate(R.layout.screen_video, container, false);

mVideoView = (VideoView) fragmentView.findViewById(R.id.VideoView);

return fragmentView;
}


@Override
public void onPause() {
super.onPause();

// Pause the video if it is playing
if (mVideoView.isPlaying()) {
mVideoView.pause();
}

// Save the current video position
mPosition = mVideoView.getCurrentPosition();
}

@Override
public void onResume() {
super.onResume();

mVideoView.setOnCompletionListener(this);
mVideoView.setOnPreparedListener(this);
mVideoView.setOnErrorListener(this);
mVideoView.setKeepScreenOn(true);

// Initialize the media controller
MediaController mediaController = new MediaController(getActivity());
mediaController.setMediaPlayer(mVideoView);
// Set-up the video view
mVideoView.setMediaController(mediaController);
mVideoView.requestFocus();
mVideoView.setVideoPath(mVideo.getUrl());

if (mVideoView != null) {
// Restore the video position
mVideoView.seekTo(mPosition);
mVideoView.requestFocus();
}
}

@Override
public void onDestroy() {
super.onDestroy();

// Clean-up
if (mVideoView != null) {
mVideoView.stopPlayback();
mVideoView = null;
}
}

@Override
public void onCompletion(MediaPlayer mediaPlayer) {
Log.e("VIDEO PLAY", "end video play");
}

@Override
public void onPrepared(MediaPlayer mediaPlayer) {
// Start the video view
mediaPlayer.start();
Log.e("VIDEO PLAY", "video ready for playback");
}

@Override
public boolean onError(MediaPlayer mediaPlayer, int i, int i1) {
Log.e("VIDEO PLAY", "error: " + i);
return true;
}

}

我不认为它与上下文(应用程序或 Activity )有关..因为在所有其他设备上显示视频和游戏..感谢您的帮助!

最佳答案

我有一个类似的问题,我通过更改解决了它:

 MediaController mediaController = new MediaController(getActivity().getApplicationContext());

对此(在 fragment 中):

 MediaController mediaController = new MediaController(getActivity());

希望这有帮助,...

编辑

看看这个类

http://code.google.com/p/sinaweibo-honeycomb/source/browse/branches/sinaweibo-merged/src/com/lenovo/dll/SinaWeibo/VideoFragment.java?r=71

关于android - VideoView 不显示在 fragment 上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13489290/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com