//視頻播放器android
VideoView vv=(VideoView) findViewById(R.id.videoView1); //設置播放路徑 ///data/media/0/local/abc.MP4 ///data/iToolsVMShare/minion_09.mp4 vv.setVideoPath("data/media/0/local/abc.MP4"); MediaController control=new MediaController(this); control.setMediaPlayer(vv); vv.setMediaController(control); //開始播放 vv.start();
//佈局ide
<VideoView android:id="@+id/videoView1" android:layout_width="match_parent" android:layout_height="200dp"
//權限佈局
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="16" />
//音頻播放器this
public void mplay(View v){ if(falg){ //1.建立對象 mp=new MediaPlayer(); try { //2.設置數據源--sd卡的路徑 /sdcard/xxx.mp3 // mp.setDataSource("/data/iToolsVMShare/bajie.mp3");//在iTools模擬器下 mp.setDataSource("/sdcard/Music/Over_the_horizon.mp3");//-在原生模擬器 //3.準備-進入準備狀態 mp.prepare(); //4.開始播放 mp.start(); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (SecurityException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalStateException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }else{ //繼續播 mp.start(); } } public void mpause(View v){ if(mp!=null){ mp.pause(); falg=false; } } public void mstop(View v){ if(mp!=null){ mp.stop(); falg=true; } }
//佈局spa
<Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_marginLeft="36dp" android:layout_marginTop="60dp" android:text="播放" android:onClick="mplay" /> <Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/button1" android:layout_below="@+id/button1" android:layout_marginTop="43dp" android:text="暫停" android:onClick="mpause" /> <Button android:id="@+id/button3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/button2" android:layout_below="@+id/button2" android:layout_marginTop="38dp" android:text="中止" android:onClick="mstop" />
//權限3d
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="17" />