开发者

How to access video in Surface view

I am doing multimedia application. I have tried several different examples to implement videos in surface view but I cannot get. i can hear the sound but no visual is appearing. is there any possibilities to get a video in surface view. My target SDK is开发者_如何学C 2.2 API level 8. Even I installed my apk to mobile device, still nothing will changed. Please guide me.


I'm not sure how you want to play your video, stream it or copy it to your sdcard or in the /res folder but I've got the following to play video. I can choose whether to stream it or play from a folder on my sdcard

Video.java

import android.app.Activity;
import android.os.Bundle;
import android.widget.VideoView;

public class Movie extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);


        setContentView(R.layout.video_layout);
        VideoView video = (VideoView) findViewById(R.id.movie);

        //this is the place where you define where to get the video from (this can be from your sd or a stream)
        video.setVideoPath(
        "/sdcard/video/videofile.mp4"

        /*"rtsp://Youtube Stream*/
                );

        //after the video is loaded it will then start
        video.start();
    }
}

video_layout.xml

    <?xml version="1.0" encoding="utf-8"?>
<FrameLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" >
    <VideoView
        android:id="@+id/movie"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_gravity="center">
    </VideoView>    
</FrameLayout>

Hope this will help you! I also had several problems with SurfaceView but this way my problems were solved.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜