开发者

Black screen rendered when playing YouTube video by SurfaceView?

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 sol开发者_运维技巧ve 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){}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜