Objective
This chapter continues to improve the playback of the relevant player's core functions, for subsequent expansion lay a good foundation.
Series
1.Android uses Vitamio to build its own universal player (1)--ready
Body
I. Achievement of the goal
1.1 Brightness Control
Imitate the Vplayer interface:
1.2 Voice Control
Imitate the Vplayer interface:
1.3 Screen Zoom
According to the following API to provide the picture stretch, cut, 100%, full screen
Second, Vitamio API introduction
Videoview
2.1 public void Start ()
Start playing
2.2 public void Pause ()
Pause Playback
2.3 Public long getduration ()
Gets the length of the video
2.4 Public long GetCurrentPosition ()
Gets the length of time that has been played
2.5 public void Seekto (long msec)
Sets the player to start playing from a specified location
2.6 Public Boolean isplaying ()
is playing
2.7 public int getvideowidth ()
Get video width
2.8 public int Getvideoheight ()
Get Video High
2.9 public void setbuffersize (int bufsize)
Set cache size, default 1024KB
2.10 public void setvideoquality (int quality)
Set video quality, Low, medium, and High (Mediaplayer.videoquality_low, Mediaplayer.videoquality_medium, Mediaplayer.videoquality_high),
The default is low (most fluid).
2.11 public void Setsubshown (Boolean shown)
Set whether captions are displayed
2.12 public void Setaudiotrack (int audioindex)
Set the audio track, which must be a getaudiotrackmap (String) return value.
2.13 public void SetVolume (float leftvolume, float rightvolume)
Set stereo sound volume.
2.14 public void Setsubpath (String subpath)
Set the external caption path
2.15 public int Getbufferpercentage ()
Get buffer percent
2.16 public void Stopplayback ()
Stop playing
2.17 public void Setvideopath (String path)
Set the video playback path
2.18 public void Setvideouri (URI uri)
Set the video playback path
2.19 public void Setvideolayout (int layout, float aspectratio)
Set video scaling (stretch, cut, 100%, full screen)
Third, the implementation of the Code
3.1 XML
<?xml version= "1.0" encoding= "Utf-8"?> <relativelayout xmlns:android= "http://schemas.android.com/apk/res/" Android "android:orientation=" vertical "android:layout_width=" match_parent "android:layout_height=" Match_parent "
> <io.vov.vitamio.widget.videoview android:id= "@+id/surface_view" android:layout_width= "Match_parent" android:layout_height= "Match_parent" android:layout_centerhorizontal= "true" android:layout_centervertical= "true" /> <framelayout android:id= "@+id/operation_volume_brightness" android:visibility= "Invisible" android:layout_ Centerinparent= "true" android:layout_width= "Wrap_content" android:layout_height= "Wrap_content" Android:background = "#00000000" android:orientation= "horizontal" android:padding= "0dip" > <imageview android:id= "@+id/operation_" BG "android:layout_gravity=" center "android:src=" "@drawable/video_volumn_bg" android:layout_width= "Wrap_content" android:layout_height= "Wrap_content"/> <framelayout android:layout_gravity= "bOttom|center_horizontal "android:layout_width=" wrap_content "android:layout_height=" Wrap_content "Android: paddingbottom= "25dip" > <imageview android:id= "@+id/operation_full" android:layout_gravity= "left" android:src = "@drawable/video_num_bg" android:layout_width= "94dip" android:layout_height= "wrap_content"/> <imageview Android:id= "@+id/operation_percent" android:layout_gravity= "left" android:src= "@drawable/video_num_front" Android
: layout_width= "0dip" android:layout_height= "wrap_content" android:scaletype= "Matrix"/> </FrameLayout>
</FrameLayout> </RelativeLayout>
3.2 activity
/** * * Android Universal Player * */public class Videoviewdemo extends activity {private String Path = environment.
getExternalStorageDirectory () + "/moon.mp4";
Private Videoview Mvideoview;
Private View mvolumebrightnesslayout;
Private ImageView MOPERATIONBG;
Private ImageView moperationpercent;
Private Audiomanager Maudiomanager;
/** Maximum Voice * * private int mmaxvolume;
/** Current Voice */private int mvolume =-1;
/** Current Brightness * * private float mbrightness = -1f;
/** Current ZOOM mode */private int mlayout = Videoview.video_layout_zoom;
Private Gesturedetector Mgesturedetector;
Private Mediacontroller Mmediacontroller;
@Override public void OnCreate (Bundle icicle) {super.oncreate (icicle);
Setcontentview (R.layout.videoview);
Mvideoview = (videoview) Findviewbyid (R.id.surface_view);
Mvolumebrightnesslayout = Findviewbyid (r.id.operation_volume_brightness);
MOPERATIONBG = (ImageView) Findviewbyid (R.ID.OPERATION_BG); Moperationpercent = (ImageView) Findviewbyid (R.id.operation_percenT);
Maudiomanager = (Audiomanager) getsystemservice (Context.audio_service);
Mmaxvolume = Maudiomanager. Getstreammaxvolume (Audiomanager.stream_music);
Mvideoview.setvideopath (path);
Mmediacontroller = new Mediacontroller (this);
Mvideoview.setmediacontroller (Mmediacontroller);
Mvideoview.requestfocus ();
Mgesturedetector = new Gesturedetector (This, new Mygesturelistener ());
@Override public boolean ontouchevent (Motionevent event) {if (Mgesturedetector.ontouchevent (event)) return true;
Handle gesture End switch (event.getaction () & Motionevent.action_mask) {case MotionEvent.ACTION_UP:endGesture ();
Break
Return Super.ontouchevent (event);
/** gesture End/private void Endgesture () {mvolume =-1;
mbrightness = -1f;
Hidden mdismisshandler.removemessages (0);
Mdismisshandler.sendemptymessagedelayed (0, 500); Private class Mygesturelistener extends Simpleongesturelistener {/** Double-click * * @Override public boolean Ondoubletap (Motionevent e) {if (MLAyout = = videoview.video_layout_zoom) Mlayout = Videoview.video_layout_origin;
else mlayout++;
if (Mvideoview!= null) mvideoview.setvideolayout (mlayout, 0);
return true; /** Sliding */@Override public boolean onscroll (Motionevent E1, motionevent E2, float Distancex, float Distancey) {f
Loat moldx = E1.getx (), moldy = E1.gety ();
int y = (int) E2.getrawy ();
Display disp = Getwindowmanager (). Getdefaultdisplay ();
int windowwidth = Disp.getwidth ();
int windowheight = Disp.getheight ();
if (Moldx > WindowWidth * 4.0/5)/Right sliding onvolumeslide ((moldy-y)/windowheight);
else if (MOLDX < windowwidth/5.0)//Left Sliding onbrightnessslide ((moldy-y)/windowheight);
Return Super.onscroll (E1, E2, Distancex, Distancey); }/** timed to hide/private Handler Mdismisshandler = new Handler () {@Override public void Handlemessage (msg)
{mvolumebrightnesslayout.setvisibility (View.gone);
}
}; /** * Sliding change sound size * * @param percent * * private void Onvolumeslide(float percent)
{if (Mvolume = = 1) {Mvolume = Maudiomanager.getstreamvolume (Audiomanager.stream_music);
if (Mvolume < 0) Mvolume = 0;
Display Moperationbg.setimageresource (R.DRAWABLE.VIDEO_VOLUMN_BG);
Mvolumebrightnesslayout.setvisibility (view.visible);
int index = (int) (Percent * mmaxvolume) + Mvolume;
if (Index > Mmaxvolume) index = Mmaxvolume;
else if (Index < 0) index = 0;
Change Sound Maudiomanager.setstreamvolume (audiomanager.stream_music, index, 0);
Change progress bar Viewgroup.layoutparams LP = Moperationpercent.getlayoutparams ();
Lp.width = Findviewbyid (r.id.operation_full). Getlayoutparams (). Width * Index/mmaxvolume;
MOPERATIONPERCENT.SETLAYOUTPARAMS (LP);
/** * Sliding Change brightness * * @param percent * * private void onbrightnessslide (float percent) {if (Mbrightness < 0) {
Mbrightness = GetWindow (). GetAttributes (). screenbrightness;
if (mbrightness <= 0.00f) mbrightness = 0.50f;
if (Mbrightness < 0.01f) mbrightness = 0.01f; Show MOpErationbg.setimageresource (R.DRAWABLE.VIDEO_BRIGHTNESS_BG);
Mvolumebrightnesslayout.setvisibility (view.visible);
} windowmanager.layoutparams LPA = GetWindow (). GetAttributes ();
Lpa.screenbrightness = mbrightness + percent;
if (lpa.screenbrightness > 1.0f) lpa.screenbrightness = 1.0f;
else if (Lpa.screenbrightness < 0.01f) lpa.screenbrightness = 0.01f;
GetWindow (). SetAttributes (LPA);
Viewgroup.layoutparams LP = Moperationpercent.getlayoutparams ();
Lp.width = (int) (Findviewbyid (R.id.operation_full). Getlayoutparams (). Width * lpa.screenbrightness);
MOPERATIONPERCENT.SETLAYOUTPARAMS (LP); @Override public void onconfigurationchanged (Configuration newconfig) {if (Mvideoview!= null) mvideoview.setvide
Olayout (mlayout, 0);
Super.onconfigurationchanged (Newconfig); }
}
3.3 Code Description
3.3.1 Zoom function
The SDK already provides a good interface for direct use.
3.3.2 Volume and brightness control implementation
Depending on the layout, you can see that using the Framelayout feature (the back view overwrites the front view) to achieve the effect of the progress bar by controlling the width of the latter view.
3.3.3 Auto Hide
The handle can be used to realize the function of the custom time delay hiding, and it is more practical.
3.3.4 gestures
Gestures can be used to search for more information on gesturedetector, double-click, zoom gestures are achievable.
Four, code download
Please go to #taocode (SVN): (please register an account without an account.) )
Project Address: Http://code.taobao.org/p/oplayer
V. Vitamio Related Information
5.1 A new SDK version will be released in the near future
5.1.1 will be directly built into each platform decoder, no need for external download!
5.1.2 will support custom progress control bars, and so on.
Vi. related articles
6.1 Android Slide screen to adjust screen brightness when playing movies
6.2 Android MediaPlayer API
End
This series of articles promises to make at least one article a week to help needy friends integrate Vitamio into their own or company projects as soon as possible.
The above is to the Android Vitamio data collation, follow-up continue to add.