VideoView上没有一个片段显示片段、VideoView

2023-09-05 06:04:05 作者:凝眸处,又添一段新愁

我在三星S3(安卓4.1.1)上运行的视频有问题,这个问题似乎是因为videoview是一个片段,因为如果我把它放在和活动,它的工作原理。 此外,我发现,如果我打开的GPU硬件加速,视频作品。 我也有一个游戏由一个SurfaceView绘图和观点并没有很好地工作(仅适用于GPU上的)......显示在应用程序内容的其余部分,因为它应该(按钮和其他布局)。

I have a problem in running a video in Samsung S3(Android 4.1.1), the issue seems to be because the videoview is on a fragment because if I put it on and activity, it works. Also I found out that if I turn on the GPU hardware acceleration on, the video works. I have also a game made by drawing on a SurfaceView and that view doesn't work as well(only with GPU on)... The rest of the app content is displayed as it supposed to (buttons and other layouts).

我测试在Nexus S和模拟器上的应用程序,并能正常工作,还对其他设备。

I tested the app on Nexus S and on the emulator and it works fine, also on other devices..

有谁知道什么问题可能是什么? 谢谢!

Does anyone know what the problem could be? Thank you!

这里是code:

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;
    }

}

我不认为这是一些相关的上下文(应用程序或活动)..因为在视频和游戏显示的所有其他设备... 感谢您的帮助!

I don't think it's something related to context(Application or Activity).. because on all other devices the Video and the games are displayed.. Thanks for the help!

推荐答案

如果硬件加速解决您的问题,那么我会的启用该设备上的视图/窗口。

If hardware acceleration fixes your issue then I would enable it for that view/window on that device.

在一般我发现,当code工作在一个设备上,但不是另一个它通常是由下列问题之一:

In general I've found that when code works on one device but not another it is typically caused by one of the following problems:

的Bug在制造商的API实现 API的制造商不同的跨pretation 在自己的code并发问题(如竞争状态,不正确的同步),恰好触发更频繁地在特定设备上

据我可以告诉你似乎可以用UI线程适当的,所以我会想象你的问题属于前两类之一,你只需要解决它。

As far as I can tell you seem to be using the UI thread appropriately so I would imagine your issue falls into one of the first two categories and you'll just need to work around it.