Basic functions of mobile audio 4--video player

Source: Internet
Author: User
Tags session id

1.MediaPlayer and Videoview Introduction

The Android system provides developers with multimedia applications (audio and video)

One, MediaPlayer,

Decoding is the bottom, MediaPlayer is responsible for dealing with the bottom, encapsulated a lot of methods Start,pause,stop, play the video class

This mediaplayer can play local and network audio and video playback network resources when the Internet access rights

1, execution process

2. Video supported formats mp4,3gp,.m3u8 directly with the. mp4 file of the PC

Two, Videoview

Display video, Inherit Surfaceview class, implement MediaPlayerControl interface, encapsulate MediaPlayer start,pause,stop, essentially call MediaPlayer

Surfaceview video principles and Small stories

Surfaceview, which uses double buffering technology by default, supports drawing images in sub-threads so that the main thread is not blocked, so it is more suitable for game and video player development

Implements the MediaPlayerControl interface, facilitates the control panel to call the Videoview method

Public interface MediaPlayerControl {        void    start ();        void    pause ();        int     getduration ();        int     getcurrentposition ();        void    seekto (int pos);        Boolean isplaying ();        int     getbufferpercentage ();        Boolean canpause ();        Boolean Canseekbackward ();        Boolean Canseekforward ();        /**         * Get The audio session ID for the player used by this videoview. This can is used to         * Apply audio effects to the audio track of a video.         * @return The audio session, or 0 if there is an error.         *     /int Getaudiosessionid ();    }

Videoview.setmediacontroller (New Mediacontroller (this));

2. Top of the player control bar

1 <LinearLayout2     Android:id= "@+id/ll_top"3 Android:layout_width= "Match_parent"4 Android:layout_height= "Wrap_content"5 android:orientation= "vertical">6 7     <LinearLayout8         Android:layout_width= "Match_parent"9 Android:layout_height= "Wrap_content"Ten Android:background= "@drawable/bg_player_status" One android:gravity= "Center_vertical" A android:orientation= "Horizontal"> -  -         <TextView the             Android:id= "@+id/tv_name" - Android:layout_width= "Wrap_content" - Android:layout_height= "Wrap_content" - Android:layout_marginleft= "8DP" + Android:layout_weight= "1" - Android:text= "Video name" + Android:textcolor= "#ffffff" /> A  at         <ImageView -             Android:id= "@+id/iv_battery" - Android:layout_width= "Wrap_content" - Android:layout_height= "Wrap_content" - Android:layout_marginright= "8DP" - android:src= "@drawable/ic_battery_10" /> in  -         <TextView to             Android:id= "@+id/tv_system_time" + Android:layout_width= "Wrap_content" - Android:layout_height= "Wrap_content" the Android:layout_marginleft= "8DP" * Android:layout_marginright= "8DP" $ Android:text= "12:00pm"Panax Notoginseng Android:textcolor= "#ffffff" /> -     </LinearLayout> the  +  A     <LinearLayout the         Android:layout_width= "Match_parent" + Android:layout_height= "Wrap_content" - Android:background= "@drawable/bg_player_top_control" $ android:gravity= "Center_vertical" $ android:orientation= "Horizontal"> -  -         <Button the             Android:id= "@+id/btn_voice" - Wuyi Android:layout_width= "Wrap_content" the Android:layout_height= "Wrap_content" - Android:background= "@drawable/btn_voice_selector" /> Wu  -         <SeekBar About             Android:id= "@+id/seekbar_voice" $ Android:layout_width= "Match_parent" - Android:layout_height= "Wrap_content" - Android:layout_weight= "1" - Android:maxheight= "6DP" A Android:minheight= "6DP" + android:progressdrawable= "@drawable/progress_horizontal" the Android:thumb= "@drawable/progress_thumb" /> -  $         <Button the             Android:id= "@+id/btn_swich_player" the Android:layout_width= "Wrap_content" the Android:layout_height= "Wrap_content" the Android:background= "@drawable/btn_swich_player_selector" /> -  in     </LinearLayout> the  the  About </LinearLayout>
View Code

3.

Basic functions of mobile audio 4--video player

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.