无法播放视频,但在Android的Live Streaming上音频播放正常 [英] Video not playing but audio plays fine on Live Streaming in android

查看:144
本文介绍了无法播放视频,但在Android的Live Streaming上音频播放正常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个VideoView,用于播放直播.我找不到问题发生的位置.

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

一开始,我使用 RTMP 使用 Vitamio 播放实时流,导致播放音频而使屏幕空白.我使用RTMP链接签出了,它在网站上可以正常工作.我对此进行了很多冲浪,但是没有找到任何解决方案.

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.

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

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).

我期望使用 RTMP HTTP 的解决方案.

I am expecting a solution for either RTMP or HTTP.

任何建议?

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

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.

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

On the other hand, having the RTMP link working fine, it doesn't solve the problem when using Vitamio. Any Suggestions for 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);
            }
        });
    }
}

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

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

在这里我添加了屏幕截图

Here I have added the screenshot

推荐答案

我已经做到了,这里的代码很好用

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

修改后的答案

我已经在vitamio库演示样本上测试了流式传输,并且工作正常.

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

公共类VideoViewDemo扩展了活动{

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

}

和xml布局

<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 .

这篇关于无法播放视频,但在Android的Live Streaming上音频播放正常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆