SurfaceView播放YouTube视频时黑屏?
我使用 SurfaceView 在 Android 应用程序上播放 YouTube rtsp 视频。声音很好,但屏幕上只呈现黑屏。相同的视频在 VideoView 上播放得很好,但我需要在控件上进行一些自定义。
以下是我使用的代码片段。有人可以帮我解决这个问题吗?非常感谢:)
String src = "rtsp://v2.cache2.c.youtube.com/CjYLENy73wIaLQm3JbT_9HqWohMYESARFEIJbXYtZ29vZ2xlSARSBXdhdGNoYIvJo6nmx9DvSww=/0/0/0/video.3gp";
SurfaceView surfaceView = new SurfaceView(this);
setContentView(surfaceView);
SurfaceHolder surfaceHolder = surfaceView.getHolder();
surfaceHolder.setFixedSize(480, 360);
surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
MediaPlayer mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.setDisplay(surfaceHolder);
try
{
mediaPlayer.setDataSource(src);
mediaPlayer.prepare();
mediaPlayer.start();
}
catch (Exception e){}
I use SurfaceView to play a YouTube rtsp video on my Android app. The sound is fine, but only a black screen rendered on the screen. Same video plays very well on VideoView, but I need to do some customizaton on the control.
The following is the code snippet I used. Could someone help me solve this problem? Thanks very much:)
String src = "rtsp://v2.cache2.c.youtube.com/CjYLENy73wIaLQm3JbT_9HqWohMYESARFEIJbXYtZ29vZ2xlSARSBXdhdGNoYIvJo6nmx9DvSww=/0/0/0/video.3gp";
SurfaceView surfaceView = new SurfaceView(this);
setContentView(surfaceView);
SurfaceHolder surfaceHolder = surfaceView.getHolder();
surfaceHolder.setFixedSize(480, 360);
surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
MediaPlayer mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.setDisplay(surfaceHolder);
try
{
mediaPlayer.setDataSource(src);
mediaPlayer.prepare();
mediaPlayer.start();
}
catch (Exception e){}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论