视频无法播放,但音频在Android

时间:2016-09-17 11:34:04

标签: android audio video rtmp http-live-streaming

我有VideoView用来播放直播。我无法找到问题发生的位置。

开始时,我使用 RTMP 来播放使用 Vitamio 的直播,这导致播放音频,使屏幕留空。我查看了RTMP链接,它可以正常使用网站。我对此进行了很多讨论,但我找不到任何解决方案。

所以现在,我切换到 HTTP 播放实时流,这也会导致同样的问题(即音频播放正常,但视频是空白的)。

我期待 RTMP HTTP 的解决方案。

任何建议???

更新1:我发现链接有问题。我使用VLC Media Player来检查我的RTMP和HTTP链接是否正常工作。 RTMP 链接正常,而问题出在 HTTP 链接上。 HTTP链接仅播放音频。

另一方面,让RTMP链接正常工作,使用 Vitamio 时无法解决问题。对RTMP的任何建议??

这是我的代码:

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();

     }
}

更新2:

以下是使用 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);
            }
        });
    }
}

我得到相同的结果(即)正在播放音频但视频为空白。

这里我添加了截图

screenshot

2 个答案:

答案 0 :(得分:1)

您可以创建此类活动以打开默认视频视图

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();
            }
        });

    }
}

答案 1 :(得分:1)

我已经完成了这个,它的工作正常是代码

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" />

已编辑的答案

我已经测试过vitamio库演示样本的流媒体及其工作正常。

公共类VideoViewDemo扩展了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);
        }
    });
}

}

和xml布局,

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

enter image description here

现在我确信代码运行良好。

谢谢希望这会对你有所帮助。