RTSP直播在Android上

我尝试在Android上进行直播。 我尝试了很多方法,但都没有工作。 我该怎么做?

这是RTSP的例子:

mMediaPlayer = new MediaPlayer(); mMediaPlayer.setDataSource(KralStream.getTvStreamUrl().toString()); mMediaPlayer.setDisplay(holder); mMediaPlayer.prepareAsync(); mMediaPlayer.setOnBufferingUpdateListener(this); mMediaPlayer.setOnCompletionListener(this); mMediaPlayer.setOnPreparedListener(this); mMediaPlayer.setOnVideoSizeChangedListener(this); mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); mMediaPlayer.setLooping(true); 

执行:05-26 10:22:46.186:
ERROR / MediaPlayerService(10157):
创buildPVPlayer 05-26 10:23:06.382:
错误/ PlayerDriver(10157):命令
PLAYER_INIT完成了一个错误或
info -1 05-26 10:23:06.382:
错误/ MediaPlayer(23800):错误(1,
-1)05-26 10:23:06.382:错误/ MediaPlayer(23800):错误(1,-1)

RTSP:

 VideoView videoView = (VideoView)findViewById(R.id.videoView1); Uri uri = Uri.parse("rtsp://strm-3.tr.medianova.tv/rkraltv/rkraltv"); videoView.setVideoURI(uri); videoView.start(); 

它给出了这个消息:

“对不起,这个video
不能玩了。“解雇; 05-26
10:40:08.979:
ERROR / MediaPlayerService(10157):
创buildPVPlayer 05-26 10:40:09.188:
INFO / ActivityManager(10163):显示
活动
com.giantrabbit.nagare / .KralTvNow:433
毫秒(总计433毫秒)05-26 10:40:11.702:
WARN / PowerManagerService(10163):定时器
0x3-> 0x3 | 0x1 05-26 10:40:29.061:
WARN / MediaPlayer(24284):info / warning
(1,26)05-26 10:40:29.061:
INFO / MediaPlayer(24284):信息(1,26)
05-26 10:40:29.100:
错误/ PlayerDriver(10157):命令
PLAYER_INIT完成了一个错误或
info -1 05-26 10:40:29.104:
错误/ MediaPlayer(24284):错误(1,
-1)05-26 10:40:29.108:错误/ MediaPlayer(24284):错误(1,-1)

RTSP:

 mPreview = (SurfaceView) findViewById(R.id.surface); holder = mPreview.getHolder(); holder.addCallback(this); holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); extras = getIntent().getExtras(); public void play() { try { Uri video = KralStream.getTvStreamUrl(); Toast.makeText(this, video.toString(), Toast.LENGTH_SHORT).show(); mMediaPlayer = new MediaPlayer(); mMediaPlayer.setDataSource(path); mMediaPlayer.setDisplay(holder); mMediaPlayer.prepare(); mMediaPlayer.setOnBufferingUpdateListener(this); mMediaPlayer.setOnCompletionListener(this); mMediaPlayer.setOnPreparedListener(this); mMediaPlayer.setOnVideoSizeChangedListener(this); mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); } catch (Exception e) { Log.e(TAG, "error: " + e.getMessage(), e); } } 

Exeption:

05-26 10:36:57.589:
ERROR / MediaPlayerService(10157):
创buildPVPlayer 05-26 10:37:20.542:
错误/ PlayerDriver(10157):命令
PLAYER_INIT完成了一个错误或
info -1 05-26 10:37:20.542:
错误/ MediaPlayer(24240):错误(1,
-1)05-26 10:37:20.565:WARN / PlayerDriver(10157):
PVMFInfoErrorHandlingComplete 05-26
10:37:20.682:
错误/ MediaPlayerDemo(24240):错误:
准备失败:状态= 0x1 05-26
10:37:20.682:
ERROR / MediaPlayerDemo(24240):
java.io.IOException:准备失败:
状态= 0x1 05-26 10:37:20.682:
错误/ MediaPlayerDemo(24240):在
android.media.MediaPlayer.prepare(母语
方法)05-26 10:37:20.682:
错误/ MediaPlayerDemo(24240):在
com.giantrabbit.nagare.KralTvNow.play(KralTvNow.java:162)
05-26 10:37:20.682:
错误/ MediaPlayerDemo(24240):在
com.giantrabbit.nagare.KralTvNow.surfaceCreated(KralTvNow.java:215)
05-26 10:37:20.682:
错误/ MediaPlayerDemo(24240):在
android.view.SurfaceView.updateWindow(SurfaceView.java:536)
05-26 10:37:20.682:
错误/ MediaPlayerDemo(24240):在
android.view.SurfaceView.dispatchDraw(SurfaceView.java:339)
05-26 10:37:20.682:
错误/ MediaPlayerDemo(24240):在
android.view.ViewGroup.drawChild(ViewGroup.java:1638)
05-26 10:37:20.682:
错误/ MediaPlayerDemo(24240):在
android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
05-26 10:37:20.682:
错误/ MediaPlayerDemo(24240):在
android.view.ViewGroup.drawChild(ViewGroup.java:1638)
05-26 10:37:20.682:
错误/ MediaPlayerDemo(24240):在
android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
05-26 10:37:20.682:
错误/ MediaPlayerDemo(24240):在
android.view.View.draw(View.java:6796)
05-26 10:37:20.682:
错误/ MediaPlayerDemo(24240):在
android.widget.FrameLayout.draw(FrameLayout.java:352)
05-26 10:37:20.682:
错误/ MediaPlayerDemo(24240):在
android.view.ViewGroup.drawChild(ViewGroup.java:1640)
05-26 10:37:20.682:
错误/ MediaPlayerDemo(24240):在
android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
05-26 10:37:20.682:
错误/ MediaPlayerDemo(24240):在
android.view.View.draw(View.java:6796)
05-26 10:37:20.682:
错误/ MediaPlayerDemo(24240):在
android.widget.FrameLayout.draw(FrameLayout.java:352)
05-26 10:37:20.682:
错误/ MediaPlayerDemo(24240):在
com.android.internal.policy.impl.PhoneWindow $ DecorView.draw(PhoneWindow.java:1894)
05-26 10:37:20.682:
错误/ MediaPlayerDemo(24240):在
android.view.ViewRoot.draw(ViewRoot.java:1407)
05-26 10:37:20.682:
错误/ MediaPlayerDemo(24240):在
android.view.ViewRoot.performTraversals(ViewRoot.java:1163)
05-26 10:37:20.682:
错误/ MediaPlayerDemo(24240):在
android.view.ViewRoot.handleMessage(ViewRoot.java:1727)
05-26 10:37:20.682:
错误/ MediaPlayerDemo(24240):在
android.os.Handler.dispatchMessage(Handler.java:99)
05-26 10:37:20.682:
错误/ MediaPlayerDemo(24240):在
android.os.Looper.loop(Looper.java:123)
05-26 10:37:20.682:
错误/ MediaPlayerDemo(24240):在
android.app.ActivityThread.main(ActivityThread.java:4627)
05-26 10:37:20.682:
错误/ MediaPlayerDemo(24240):在
java.lang.reflect.Method.invokeNative(母语
方法)05-26 10:37:20.682:
错误/ MediaPlayerDemo(24240):在
java.lang.reflect.Method.invoke(Method.java:521)
05-26 10:37:20.682:
错误/ MediaPlayerDemo(24240):在
com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:871)
05-26 10:37:20.682:
错误/ MediaPlayerDemo(24240):在
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:629)
05-26 10:37:20.682:
错误/ MediaPlayerDemo(24240):在
dalvik.system.NativeStart.main(母语
方法)05-26 10:37:20.737:
INFO / MediaPlayer(24240):信息(1,26)
05-26 10:37:20.737:
错误/ MediaPlayer(24240):错误(1,-1)
05-26 10:37:20.868:
INFO / ActivityManager(10163):显示
活动
com.giantrabbit.nagare / .KralTvNow:
25864毫秒(共25864毫秒)05-26
10:37:23.777:
WARN / PowerManagerService(10163):定时器
0x3-> 0x3 |为0x1

这是一个HTTP的例子:

 mMediaPlayer = new MediaPlayer(); mMediaPlayer.setDataSource("http://ikral.garantisistem.com:1935/ikral/smil:kral.smil/playlist.m3u8"); mMediaPlayer.setDisplay(holder); mMediaPlayer.prepareAsync(); mMediaPlayer.setOnBufferingUpdateListener(this); mMediaPlayer.setOnCompletionListener(this); mMediaPlayer.setOnPreparedListener(this); mMediaPlayer.setOnVideoSizeChangedListener(this); mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); mMediaPlayer.setLooping(true); 

例外:

05-26 10:16:24.276:
ERROR / MediaPlayerService(10157):
创buildPVPlayer 05-26 10:16:24.292:
错误/(10157):IIIIIII里面
构造函数
PVMFMemoryBufferWriteDataStreamImpl
05-26 10:16:24.346:
INFO / PlayerDriver(10157):缓冲
(100)05-26 10:16:24.346:
错误/(10157):IIIIIII里面
构造函数
PVMFMemoryBufferReadDataStreamImpl
05-26 10:16:24.346:错误/(10157):
IIIIIII内部构造函数
PVMFMemoryBufferReadDataStreamImpl
05-26 10:16:24.346:错误/(10157):
IIIIIII内部构造函数
PVMFMemoryBufferReadDataStreamImpl
05-26 10:16:24.346:错误/(10157):
IIIIIII内部构造函数
PVMFMemoryBufferReadDataStreamImpl
05-26 10:16:24.346:错误/(10157):
IIIIIII内部构造函数
PVMFMemoryBufferReadDataStreamImpl
05-26 10:16:24.346:错误/(10157):
IIIIIII内部构造函数
PVMFMemoryBufferReadDataStreamImpl
05-26 10:16:24.346:错误/(10157):
IIIIIII内部构造函数
PVMFMemoryBufferReadDataStreamImpl
05-26 10:16:24.346:错误/(10157):
IIIIIII内部构造函数
PVMFMemoryBufferReadDataStreamImpl
05-26 10:16:24.346:错误/(10157):
IIIIIII内部构造函数
PVMFMemoryBufferReadDataStreamImpl
05-26 10:16:24.346:错误/(10157):
IIIIIII内部构造函数
PVMFMemoryBufferReadDataStreamImpl
05-26 10:16:24.346:错误/(10157):
IIIIIII内部构造函数
PVMFMemoryBufferReadDataStreamImpl
05-26 10:16:24.346:错误/(10157):
IIIIIII内部构造函数
PVMFMemoryBufferReadDataStreamImpl
05-26 10:16:24.350:
WARN / MediaPlayer(23736):info / warning
(1,26)05-26 10:16:24.354:
错误/ PlayerDriver(10157):命令
PLAYER_INIT完成了一个错误或
info -10 05-26 10:16:24.354:
错误/ MediaPlayer(23736):错误(-10,
-10)05-26 10:16:24.354:WARN / PlayerDriver(10157):
PVMFInfoErrorHandlingComplete 05-26
10:16:24.393:INFO / MediaPlayer(23736):
信息(1,26)05-26 10:16:24.393:
错误/ MediaPlayer(23736):错误
(-10,-10)

HTTP:

 VideoView videoView = (VideoView)findViewById(R.id.videoView1); Uri uri = Uri.parse("http://ikral.garantisistem.com:1935/ikral/smil:kral.smil/playlist.m3u8"); videoView.setVideoURI(uri); videoView.start(); 

它给出的信息是:

“对不起,这个video不能播放。”

在这里输入图像说明

Solutions Collecting From Web of "RTSP直播在Android上"

请像这样在您的AndroidManifest.xml文件中添加networking权限

 <uses-permission android:name="android.permission.INTERNET" /> 

Android可以处理RTSPstream,无需任何Flash。 您尝试直接在浏览器地址栏中inputurl ,外部播放器将自动打开以播放url。

如果出现错误,则需要检查Android支持的video格式。 您可以从Wowza Media Server检查RTSPstreamURL的例子。 参考从Wowza媒体服务器的RTSPstream故障排除的URL: http ://www.wowza.com/forums/content.php?62-RTSP-streaming-troubleshooting-guide-%28RTSP-RTP-playback%29。 我希望这有帮助。

这是因为video的格式。 尝试使其3GP 。