0

我正在做多媒体应用程序。我尝试了几个不同的示例来在表面视图中实现视频,但我无法获得。我能听到声音,但没有出现视觉。有没有可能在表面视图中获得视频。我的目标 SDK 是 2.2 API 级别 8。即使我将我的 apk 安装到移动设备上,仍然没有任何改变。请指导我。

4

1 回答 1

0

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.

于 2011-01-29T10:02:14.233 回答