Video not playing but audio plays fine on Live Streaming in android

喜你入骨 提交于 2019-12-08 12:26:43

问题


I have a VideoView which is used to play live stream. I am not able to find where the problem occurs.

In the beginning, I used RTMP to play the live stream using Vitamio which resulted in playing the audio leaving the screen blank. I checked out with the RTMP link, it works fine with a website. I surfed a lot about this, but I did not find any solution.

So now, I switched to HTTP to play the live stream which also results in the same problem (i.e audio playing fine but video is blank).

I am expecting a solution for either RTMP or HTTP.

Any Suggestions???

UPDATE 1: I have found a problem with the link. I used VLC Media Player to check whether my RTMP and HTTP link is working fine or not. The RTMP link works fine whereas the problem was with the HTTP link. The HTTP link plays only the audio.

On the other hand, having the RTMP link working fine, it doesn't solve the problem when using Vitamio. Any Suggestions for RTMP??

Here is my code:

public class ITVLiveStreamActivity extends Activity {

private VideoView liveVideoView;

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

         liveVideoView = (VideoView) findViewById(R.id.liveVideoView);

         MediaController mediaController = new MediaController(this);
         mediaController.setAnchorView(liveVideoView);
         Uri uri = Uri.parse(getIntent().getStringExtra("rtmp://61.16.143.170:1935/live/7khh-8fhu-vxd3-8fuw"));
         liveVideoView.setVideoURI(uri);
         liveVideoView.setMediaController(mediaController);
         liveVideoView.requestFocus();
         liveVideoView.start();

     }
}

UPDATE 2:

Here is my code using Vitamio:

import android.app.Activity;
import android.app.ProgressDialog;
import android.os.Bundle;

import io.vov.vitamio.LibsChecker;
import io.vov.vitamio.MediaPlayer;
import io.vov.vitamio.widget.MediaController;
import io.vov.vitamio.widget.VideoView;

public class ITVLiveStreamActivity extends Activity {

    private String pathToFileOrUrl="rtmp://61.16.143.170:1935/live/7khh-8fhu-vxd3-8fuw";
    private VideoView mVideoView;
    private ProgressDialog progDailog;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if(!LibsChecker.checkVitamioLibs(this))
            return;
        setContentView(R.layout.activity_itvlive_stream);

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

        progDailog = new ProgressDialog(this);
        progDailog.setCancelable(false);
        progDailog.setMessage(getResources().getString(R.string.loading));
        progDailog.show();

        mVideoView.setVideoPath(pathToFileOrUrl);
        mVideoView.setMediaController(new MediaController(this));
        mVideoView.requestFocus();

        mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {

            @Override
            public void onPrepared(MediaPlayer mediaPlayer) {
                progDailog.dismiss();
                mediaPlayer.setPlaybackSpeed(1.0f);
            }
        });
    }
}

I am getting the same result (i.e) Audio is playing but video is blank.

Here I have added the screenshot


回答1:


You can create an activity like this to open default Video View

public class VideoViewActivity extends Activity {

    // Declare variables
    ProgressDialog pDialog;
    VideoView videoview;

    // Insert your Video URL
//      String VideoURL; /*= "http://www.androidbegin.com/tutorial/AndroidCommercial.3gp";*/
    String VideoURL;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // Get the layout from video_main.xml
        setContentView(R.layout.video_view);
        // Find your VideoView in your video_main.xml layout
        videoview = (VideoView) findViewById(R.id.VideoView);
        // Execute StreamVideo AsyncTask
        VideoURL = getIntent().getExtras().getString(Constants.LINK);
//        Log.v("video", VideoURL);
        // Create a progressbar
        pDialog = new ProgressDialog(VideoViewActivity.this);
        // Set progressbar title
        //pDialog.setTitle("Android Video Streaming Tutorial");
        // Set progressbar message
        pDialog.setMessage("Buffering...");
        pDialog.setIndeterminate(false);
        pDialog.setCancelable(false);
        // Show progressbar
        pDialog.show();

        try {
            // Start the MediaController
            MediaController mediacontroller = new MediaController(
                    VideoViewActivity.this);
            mediacontroller.setAnchorView(videoview);
            // Get the URL from String VideoURL
            Uri video = Uri.parse(VideoURL);
            videoview.setMediaController(mediacontroller);
            videoview.setVideoURI(video);

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

        } finally {
            videoview.setOnErrorListener(new OnErrorListener() {
                @Override
                public boolean onError(MediaPlayer mp, int what, int extra) {
                    CommonUtilities.showToast(VideoViewActivity.this, "Video Format not supported by device.");
                    VideoViewActivity.this.finish();
                    return true;
                }
            });
        }

        videoview.requestFocus();
        videoview.setOnPreparedListener(new OnPreparedListener() {
            // Close the progress bar and play the video
            public void onPrepared(MediaPlayer mp) {
                pDialog.dismiss();
                videoview.start();
            }
        });

    }
}



回答2:


hi i have done this and its working fine here is code

public class PlayingLiveStream extends Activity {

VideoView vvmyliveplaying;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_playinglivestream);
    vvmyliveplaying = (VideoView) findViewById(R.id.vvmyliveplaying);
    MediaController mediaController = new MediaController(this);
    mediaController.setAnchorView(vvmyliveplaying);
    Uri uri = Uri.parse(getIntent().getStringExtra("url_play"));
    vvmyliveplaying.setVideoURI(uri);
    vvmyliveplaying.setMediaController(mediaController);
    vvmyliveplaying.requestFocus();

}

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    if (item.getItemId() == android.R.id.home) {
        try {
            vvmyliveplaying.pause();
            finish();
        } catch (Exception e) {

        }
    }
    return false;

}
}

<VideoView
    android:id="@+id/vvmyliveplaying"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

Edited Answer

I have tested streaming on vitamio library demo sample and its working fine.

public class VideoViewDemo extends Activity {

private VideoView mVideoView;
private String pathToFileOrUrl ="rtmp://61.16.143.170:1935/live/7khh-8fhu-vxd3-8fuw";
private ProgressDialog progDailog;

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    if (!LibsChecker.checkVitamioLibs(this))
        return;
    setContentView(R.layout.videoview);

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


    progDailog = new ProgressDialog(this);
    progDailog.setCancelable(false);
    progDailog.setMessage("Please wait");
    progDailog.show();

    mVideoView.setVideoPath(pathToFileOrUrl);
    mVideoView.setMediaController(new MediaController(this));
    mVideoView.requestFocus();

    mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {

        @Override
        public void onPrepared(MediaPlayer mediaPlayer) {
            progDailog.dismiss();
            mediaPlayer.setPlaybackSpeed(1.0f);
        }
    });
}

}

and xml layout,

<io.vov.vitamio.widget.VideoView
    android:id="@+id/surface_view"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

Now i'm sure code work well.

Thanks hope this will help you .



来源:https://stackoverflow.com/questions/39546363/video-not-playing-but-audio-plays-fine-on-live-streaming-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!