媒体播放器有时不起作用

时间:2017-11-09 08:20:29

标签: java android video android-mediaplayer

我开发了一款可以复制视频.mp4的应用。 但有时视频会被中断,有时audio不会被复制,只会video

为什么?

我告诉你我的代码:

public class VideoViewFullScreenActivity extends AppCompatActivity {

    private VideoView mVideoView;
    private String mUrl;
    private static String TAG = VideoViewFullScreenActivity.class.getName();
    private MediaController mediaController;
    private int position = 0;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_video_view_full_screen);

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

        Intent intent = getIntent();

        String url_video_passato = intent.getStringExtra("URL_VIDEO");
        System.out.println("PASSATO?"+url_video_passato);

        if (mediaController == null) {
            mediaController = new MediaController(this);

            // Set the videoView that acts as the anchor for the MediaController.
            mediaController.setAnchorView(mVideoView);



            // Set MediaController for VideoView
            mVideoView.setMediaController(mediaController);
        }

        try {
            // ID of video file.
            /*int id = this.getRawResIdByName("myvideo");
            videoView.setVideoURI(Uri.parse("android.resource://" + getPackageName() + "/" + id));*/
            String videoUrl=url_video_passato;

            Uri uri = Uri.parse(videoUrl);

            mVideoView.setVideoURI(uri);





        } catch (Exception e) {
            Log.e("Error", e.getMessage());
            e.printStackTrace();
        }

        mVideoView.requestFocus();


        // When the video file ready for playback.
        mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {

            public void onPrepared(MediaPlayer mediaPlayer) {




                mVideoView.seekTo(position);
                if (position == 0) {
                    mVideoView.start();
                }

                // When video Screen change size.
                mediaPlayer.setOnVideoSizeChangedListener(new MediaPlayer.OnVideoSizeChangedListener() {
                    @Override
                    public void onVideoSizeChanged(MediaPlayer mp, int width, int height) {

                        // Re-Set the videoView that acts as the anchor for the MediaController
                        mediaController.setAnchorView(mVideoView);
                    }
                });
            }
        });


    }
}

视频中断时,我在logcat中收到此错误

E/ExtMediaPlayer-JNI: env->IsInstanceOf fails

并在屏幕上显示:Impossible reproduce video

此问题仅限在平板电脑上,而在智能手机上没有...我不知道为什么!

有人可以帮助我吗?

0 个答案:

没有答案