播放器测试编写

0x001 控件设置

加入VideoView控件

 <VideoView 
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/vv"
        
        />


0x002  设置activity的样式

要求横屏,并且 去掉 标题栏

<application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.NoTitleBar" >
        <activity
            android:name="com.gyarmy.media.MainActivity"
            android:label="@string/app_name"
            android:screenOrientation="landscape"
             >


0x003  播放文件

要求, 加入控制栏


package com.gyarmy.media;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.MediaController;
import android.widget.VideoView;

public class MainActivity extends Activity {
	
	private VideoView vv;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		//设置ID
		vv = (VideoView) findViewById(R.id.vv);
		MediaController mc = new MediaController(this);
		mc.setAnchorView(vv);
		
		//设置视频
		vv.setMediaController(mc);
		vv.setVideoPath("/mnt/shared/Other/xinli.mp4");
		
		vv.start();
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

}



原文链接: 播放器测试编写 版权所有,转载时请注明出处,违者必究。
注明出处格式:流沙团 ( http://www.gyarmy.com/post-150.html )

发表评论

0则评论给“播放器测试编写”