videoview oncompletionlistener没有在android中调用?

时间:2014-10-29 14:40:11

标签: android android-videoview

我在imageview和videoview中显示图像和视频,但问题出在视频时 播放onpreparedlistener但是当视频完成oncompletion listener时没有调用 当视频观看完成后,我将i增加为下一个视频或图像

它也给我这样的logcat错误,但视频正在播放

  

10-29 20:12:47.770:E / MediaPlayer(3975):错误(1,-2147483648)

private void nextVideo(String path){

        mImageview.setVisibility(View.GONE);


    if(mVideoview.getVisibility()==View.GONE){
        mVideoview.setVisibility(View.VISIBLE);

    }

    controller = new MediaController(HomeActivityNewViewPager.this);
    mVideoview.setVideoURI(Uri.parse(path));
    mVideoview.setMediaController(null);
    controller.setMediaPlayer(mVideoview);

    mVideoview.setOnPreparedListener(new OnPreparedListener() {

       public void onPrepared(MediaPlayer mp) {

                    mVideoview.start();
                    long duration = mVideoview.getDuration();
                    second=duration;
                    //handler.removeCallbacks(runnable);
                    //handler.postDelayed(runnable,second);

       }
   });


    mVideoview.setOnCompletionListener(new OnCompletionListener() {

        @Override
        public void onCompletion(MediaPlayer mp) {

               Log.v("video view completed","---"+i);

               mp.reset();

               if(automode){

                   if(i==myplaylistlocal.size() || i>myplaylistlocal.size())
                   {

                       String checkcount=spreferences.getString("roundcount", "");
                       Log.v("roundcount==Before Integer.parseInt","---->"+roundcount);
                       if(roundcount>=Integer.parseInt(checkcount))
                       {   
                           roundcount=0;
                           Log.v("roundcount==After Integer.parseInt","---->"+roundcount);
                           updateplaylist();
                       }

                       i=0;                                                
                       indexplus();
                       imagesautomode();
                       i++;

                   }
                   else if(i==myplaylistlocal.size()-1)
                   {
                       imagesautomode();
                       i++;
                   }
                   else{
                       imagesautomode();
                   }

               }
               else{
                   i++;
                   images();
               }



        }
    });

    mVideoview.setOnErrorListener(new OnErrorListener() {

        @Override
        public boolean onError(MediaPlayer mp, int what, int extra) {

            Log.v("Error in video playing","----->"+i);

            return true;
        }

    }); 

}

1 个答案:

答案 0 :(得分:0)

无论哪种方式,上面引用的错误都是MEDIA_ERROR_UNKNOWN。如果此视频是针对此应用制作的,我会确保它已针对Android进行了正确编码。还要确保明确定义其端点。

http://developer.android.com/reference/android/media/MediaPlayer.html#MEDIA_ERROR_UNKNOWN

这是一种解决方法,但可能适用于您的情况:

@Override
public boolean onError(MediaPlayer mp, int what, int extra) {
    if(what == MediaPlayer.MEDIA_ERROR_UNKNOWN) 
        //ERROR UNKNOWN - COULD BE IMPROPERLY FORMATTED VIDEO {
        //MOVE ON TO NEXT VIDEO
        //DO LOGGING
    }
}