在 Android 应用程序中播放 RTSP 流
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11274906/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Play RTSP streaming in an Android application
提问by SJSSoft
I am trying to develop an Android based application, which can play video from a live stream. This live stream is produced using Wowza Media Server.
我正在尝试开发一个基于 Android 的应用程序,它可以从实时流中播放视频。此直播流是使用Wowza Media Server制作的。
The URL is:
网址是:
rtsp://tv.hindiworldtv.com:1935/live/getpun
I have tried following code in ecliplse:
我在 ecliplse 中尝试了以下代码:
package com.kalloh.wpa;
import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.net.Uri;
import android.os.Bundle;
import android.view.Window;
import android.widget.MediaController;
import android.widget.VideoView;
public class a extends Activity {
VideoView videoView;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
//Create a VideoView widget in the layout file
//use setContentView method to set content of the activity to the layout file which contains videoView
this.setContentView(R.layout.videoplayer);
videoView = (VideoView)this.findViewById(R.id.videoView);
//add controls to a MediaPlayer like play, pause.
MediaController mc = new MediaController(this);
videoView.setMediaController(mc);
//Set the path of Video or URI
videoView.setVideoURI(Uri.parse("rtsp://tv.hindiworldtv.com:1935/live/getpnj"));
//
//Set the focus
videoView.requestFocus();
}
}
At first, it was not working.
起初,它不起作用。
Now it started working, but it stops after 20 to 30 seconds. How can I fix this problem?
现在它开始工作,但在 20 到 30 秒后停止。我该如何解决这个问题?
采纳答案by SJSSoft
I found the solution. Transmission should be within the preferred setting by Android. For more details, see Supported Media Formats.
我找到了解决方案。传输应在 Android 的首选设置内。有关更多详细信息,请参阅支持的媒体格式。
回答by Jorgesys
Using VideoViewis a good solution, but we can also use the native player
to play RTSP. This is an example:
使用VideoView是一个很好的解决方案,但我们也可以使用native player
来播放 RTSP。这是一个例子:
if (movieurl.startsWith("rtsp://")) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(movieurl));
startActivity(intent);
}
Bear in mind your media must be created with Android Supported Media Formats(codecs).
请记住,您的媒体必须使用Android 支持的媒体格式(编解码器)创建。
回答by Murali
I also had the same problem in ICS 4.x. Also, you can check whether your stream URLis working properly or not.
我在 ICS 4.x 中也遇到了同样的问题。此外,您可以检查您的流URL是否正常工作。
Also check your code with this sample URL.
还可以使用此示例 URL检查您的代码。
回答by hungson175
I had the same problem with Galaxy Note N7000 (ICS 4.0.3) and VLC 2.0.2 - the video dies after 60 seconds. But when I turn to VLC media player 1.1.4, everything just works well!
我在使用 Galaxy Note N7000 (ICS 4.0.3) 和 VLC 2.0.2 时遇到了同样的问题 - 视频在 60 秒后消失。但是当我转向 VLC 媒体播放器 1.1.4 时,一切正常!
So sometimes it depends on the media server. You can try RTSP from YouTube (go to m.youtube.com and then right click on some video -> copy location link -> that is the RTSP link you need).
所以有时它取决于媒体服务器。您可以从 YouTube 尝试 RTSP(转到 m.youtube.com,然后右键单击某个视频 -> 复制位置链接 -> 这是您需要的 RTSP 链接)。