内置影片播放器载入 3GP 电影 --VideoView

创建一个有SD 卡的模拟器( 粗体文字是命令 )

我设置了相关的环境变量

 

root@May:~/桌面# android create avd -n three -t 3 -c 128M

Android 1.6 is a basic Android platform.

Do you wish to create a custom hardware profile [no]

Created AVD 'three' based on Android 1.6,

with the following hardware config:

hw.lcd.density=240

root@May:~/桌面# android list avd

Available Android Virtual Devices:

    Name: three

    Path: /root/.android/avd/three.avd

  Target: Android 1.6 (API level 4)

    Skin: WVGA800

  Sdcard: 128M

然后往模拟器中复制一个3gp的文件

 

root@May:~/桌面# adb push /root/桌面/test.3gp /sdcard/

1355 KB/s (504030 bytes in 0.363s)

root@May:~/桌面# adb shell

# ls

sqlite_stmt_journals

cache

sdcard

etc

system

sys

sbin

proc

init.rc

init.goldfish.rc

init

default.prop

data

root

dev

# cd sdcard

# ls

LOST.DIR

test.3gp

# exit

public class Hello extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getWindow().setFormat(PixelFormat.TRANSLUCENT); // setContentView(R.layout.main); setContentView(R.layout.main); if(android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED)) existSD=true; else { existSD=false; mMakeTextToast("no sd card",true); } findview(); btn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub if(b) { b=!b; playVideo("file:///sdcard/test.3gp"); } } private void playVideo(String string) { // TODO Auto-generated method stub if(string!="") { vv.setVideoURI(Uri.parse(string)); vv.setMediaController(new MediaController(Hello.this)); vv.requestFocus(); vv.start(); if(vv.isPlaying()) { //vv. } } } }); vv.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { @Override public void onPrepared(MediaPlayer arg0) { // TODO Auto-generated method stub btn.setText("file:///sdcard/test.3gp"); } }); vv.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { @Override public void onCompletion(MediaPlayer arg) { mMakeTextToast ("finisthed",true); } }); } public void mMakeTextToast(String string, boolean b) { // TODO Auto-generated method stub if(b) Toast.makeText(Hello.this, string, Toast.LENGTH_SHORT).show(); else Toast.makeText(Hello.this, string, Toast.LENGTH_SHORT).show(); } private void findview() { vv=(VideoView)findViewById(R.id.vv); btn=(Button)findViewById(R.id.button1); } boolean existSD=false; VideoView vv; Button btn; boolean b=true; }
设置回放:
seekTo(0);
若要实现手机上网(Surf Internet )看影片的功能,只要对主程序稍作修改,即可用VideoView 观 。
在AndroidManifest.xml里添加访问权限。
<uses-permission android:name="android.permission.INTERNET">
</uses-permission>
<uses-permission android:name="android.permission.WAKE_LOCK">
</uses-permission>

file:///sdcard/test.3gp 替换成 http://somewhere.com/test.mp4

就OK了。

你可能感兴趣的:(android,String,File,basic,button,internet)