VideoView控件

ruizhenggang 2011-11-03

main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <!--
        VideoView - 视频播放控件
    -->
    <VideoView android:id="@+id/videoView" android:layout_width="wrap_content"
        android:layout_height="wrap_content">
    </VideoView>
        
</LinearLayout>

VideoviewActivity.java

package com.videoview;

import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.widget.MediaController;
import android.widget.VideoView;

public class VideoviewActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        this.setContentView(R.layout.main);

        setTitle("VideoView");
        
        VideoView videoView = (VideoView) findViewById(R.id.videoView);
        
        // 指定需要播放的视频的地址
        videoView.setVideoURI(Uri.parse("android.resource://com.webabcd.view/" + R.raw.demo));
        // videoView.setVideoPath();
         
        // 设置播放器的控制条
        videoView.setMediaController(new MediaController(this));
        // 开始播放视频
        videoView.start();
    }
}

相关推荐

huzhenv / 0评论 2010-10-06