android media player shows audio but no video

前端 未结 3 768
一整个雨季
一整个雨季 2021-01-01 04:48

I am using media player to stream a video. It only plays the audio but not the video. Could anyone help? My code is below.

public class VideoViewApplication          


        
3条回答
  •  一整个雨季
    2021-01-01 04:58

    I had this problem and solved it by adding in my release function visible=gone to surfaceview:

      public void release() {
        if (mMediaPlayer != null) {
        setVisibility(View.GONE);
          mMediaPlayer.reset();
          mMediaPlayer.release();
          mMediaPlayer = null;
          mCurrentState = STATE_IDLE;}
      }
    

    and set visible=visible in onprepared function:

       videoView.setOnPreparedListener(new OnPreparedListener() {
                public void onPrepared(MediaPlayer mp) {
                    audio=false; video=false; int ty=mp.getTrackInfo().length;
                    for (int i=0; i-1) {audio=true;}
                        if (mp.getVideoTrack()>-1) {video=true;}
                    }
    
                    if (((audio==false)&&(skip==true))||((video==false)&&(skip2==true))||((video==true)&&(skip4==true))) 
                    {   notifybar("...");
                        nexttr();} else {
                    if (vis==true) {
                    if (video==false) {
                        if (mVisualizerView.getVisibility()!=View.VISIBLE) {mVisualizerView.setVisibility(View.VISIBLE);}
                            mVisualizerView.link(videoView.getAudioSessionId());
                            vis2=true;
                            } else if (vis2==true){
                           mVisualizerView.release();
                           mVisualizerView.setVisibility(View.GONE);
                          vis2=false;
                            }}
                    //this
                    if (video==true) {
                    if (videoView.getVisibility()!=View.VISIBLE) {videoView.setVisibility(View.VISIBLE);}
                    } else {if (videoView.getVisibility()!=View.INVISIBLE) {videoView.setVisibility(View.INVISIBLE);}
                    }
    

提交回复
热议问题