Videoview
Common Methods:
Method Name |
Description |
Public void setvideopath (string path) |
Load the file in the path |
Public void setvideouri (URI) |
Load the video corresponding to the URI |
Public void start () |
Start |
Public void seekto (INT msec) |
Positioning |
Public void pause () |
Pause |
Public void stop () |
Stop |
Public void setmediacontroller (mediacontroller Controller) |
Set mediacontroller object |
About mediacontroller class
This category is also for Android. the widget package contains a mediaplayer multimedia playback component, which contains a component for "playback", "pause", "Fast forward", "Fast forward", and progress bar.
Constructor
Method Name |
Description |
Public mediacontroller (context, attributeset attrs) |
Create a mediacontroller object through the context object and attributeset object |
Public mediacontroller (context, Boolean usefastforward) |
Use the context object and specify whether to allow the user to control the progress. That is, whether there are "Fast Forward" and "Fast Return" buttons. If it is set to false, the display will not be displayed (for example, film 1) |
Public mediacontroller (context) |
Use context to create a mediacontroller object |
Common Methods
Method Name |
Description |
Public void hide () |
Set to hide mediacontroller |
Public void show () |
Set to display mediacontroller |
Public void show (INT timeout) |
Set the display time of mediacontroller in milliseconds. If it is set to 0, it will not be hidden until the hide () method is called. |
Public void setmediaplayer (mediacontroller. mediaplayercontrol player) |
Set mediaplayer to bind it with the control to be bound. The parameter is a mediacontroller. the mediaplayercontrol static interface object (while videoview is mediacontroller. mediaplayercontrol: Sub-implementation class of the static interface, which enables us to better control the video playback progress) |
Image 1
If you use the public mediacontroller (contextcontext, Boolean usefastforward) constructor to create a mediacontroller object and specify usefastforward = false, this effect is displayed.
Effect:The show and hide buttons are used to control the display and hiding of mediacontroller.
Encoding implementation:
Layout file code:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <VideoView android:id="@+id/video" android:layout_width="fill_parent" android:layout_height="fill_parent" /></LinearLayout>
Activity Code:
Package COM. jiahui. videoview; import Java. io. file; import android. app. activity; import android. graphics. pixelformat; import android. OS. bundle; import android. view. view; import android. widget. button; import android. widget. mediacontroller; import android. widget. toast; import android. widget. videoview; public class videoviewdemoactivity extends activity {private videoview; private button btnhide, btnsho W; mediacontroller; Public void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); getwindow (). setformat (pixelformat. translucent); setcontentview (R. layout. main); videoview = (videoview) This. findviewbyid (R. id. video); btnshow = (button) This. findviewbyid (R. id. btnshow); btnhide = (button) This. findviewbyid (R. id. btnhide); // using this method to create mediacontroller will not display the "Fast Forward" and "Fast Return" Buttons/me Diacontroller = new mediacontroller (this, false); mediacontroller = new mediacontroller (this); file videofile = new file ("/mnt/sdcard/movie.3gp "); // first determine whether the object exists if (videofile. exists () {system. out. println ("file exists"); videoview. setvideopath (videofile. getabsolutepath (); system. out. println (videofile. getabsolutepath (); // sets videview and mediacontroller to associate videoview. setmediacontroller (mediacontroller); // sets mediaco Ntroller and videview establish association mediacontroller. setmediaplayer (videoview); // obtain the videoview focus. requestfocus (); // start to play videoview. start ();} else {toast. maketext (this, "the file does not exist", toast. length_long ). show ();} btnshow. setonclicklistener (new view. onclicklistener () {@ overridepublic void onclick (view v) {If (mediacontroller! = NULL) {// If 0 is used, it will be displayed until hide () mediacontroller is called. show (0) ;}}); btnhide. setonclicklistener (new view. onclicklistener () {@ overridepublic void onclick (view v) {If (mediacontroller! = NULL) {mediacontroller. Hide ();}}});}}
If you need to reprint reference please indicate the source: http://blog.csdn.net/jiahui524