android media player shows audio but no video

前端 未结 3 736
一整个雨季
一整个雨季 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<ty;i++)
                    {
                        if (mp.getAudioTrack()>-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);}
                    }
    
    0 讨论(0)
  • 2021-01-01 05:01

    I had this problem and solved it by setting the type using this depreciated method.

    holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    

    Worth a try, and if it works you could investigate why the type isn't automatically set as it is supposed to be.

    0 讨论(0)
  • 2021-01-01 05:21

    I had the same problem and it was due to the surface not being ready to play back video.

    You should try and call playVideo() from the surfaceCreated() handler.

    public void surfaceCreated(SurfaceHolder holder) {
            runOnUiThread(new Runnable(){
                public void run(){
                    playVideo();
                }
            });
    }
    
    0 讨论(0)
提交回复
热议问题