gpt4 book ai didi

android - 视频无法播放,但音频在android的Live Streaming上可以正常播放

转载 作者:行者123 更新时间:2023-12-03 00:14:30 25 4
gpt4 key购买 nike

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

开始时,我使用 RTMP 使用 Vitamio 播放实时流,这导致播放音频而使屏幕空白。我通过RTMP链接 checkout ,它在网站上正常运行。我对此进行了很多冲浪,但是没有找到任何解决方案。

所以现在,我切换到 HTTP 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

最佳答案

您可以创建这样的 Activity 以打开默认的视频 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();
}
});

}
}

关于android - 视频无法播放,但音频在android的Live Streaming上可以正常播放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39546363/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com