Recently, with the help of my colleagues, I wrote the simplest player APK. Of course, it is video playing. Well, I didn't expect that the amount of code is really small...
Package videoplayer. norz; <br/> Import android. app. activity; <br/> Import android. graphics. pixelformat; <br/> Import android. media. audiomanager; <br/> Import android. OS. bundle; <br/> Import android. view. menu; <br/> Import android. view. menuitem; <br/> Import android. widget. mediacontroller; <br/> Import android. widget. videoview; <br/> public class main extends activity {<br/> Private Static final int shutdown = 0; <br/> Private Static final int open3gp = 1; <br/> Private Static final int openmp4 = 2; <br/> Private Static final int openavi = 3; </P> <p> private videoview video; <br/> private mediacontroller MC; <br/>/** called when the activity is first created. */<br/> @ override <br/> Public void oncreate (bundle savedinstancestate) {<br/> super. oncreate (savedinstancestate); <br/> getwindow (). setformat (pixelformat. transparent); <br/> setcontentview (R. layout. main); <br/> initcomponents (); <br/>}< br/> private void initcomponents () {<br/> Video = (videoview) findviewbyid (R. id. videoview); <br/> MC = new mediacontroller (this); <br/>}< br/> Public Boolean oncreateoptionsmenu (menu) {<br/> super. oncreateoptionsmenu (menu); <br/> menu. add (0, openmp4, 0, R. string. open_mp4); <br/> menu. add (0, openavi, 0, R. string. open_avi); <br/> menu. add (0, open3gp, 0, R. string. open_3gp); <br/> menu. add (0, shutdown, 0, R. string. shut_down); </P> <p> return true; <br/>}< br/> Public Boolean onoptionsitemselected (menuitem item) {<br/> switch (item. getitemid () {<br/> case open3gp: <br/> video. setvideopath ("Data/test.3gp"); <br/> MC. setmediaplayer (video); <br/> video. setmediacontroller (MC); <br/> video. start (); <br/> break; <br/> case openmp4: <br/> video. setvideopath ("Data/test.mp4"); <br/> MC. setmediaplayer (video); <br/> video. setmediacontroller (MC); <br/> video. start (); <br/> break; <br/> case openavi: <br/> video. setvideopath ("Data/test. avi "); <br/> MC. setmediaplayer (video); <br/> video. setmediacontroller (MC); <br/> video. start (); <br/> break; <br/> case shutdown: <br/> video. stopplayback (); <br/> This. finish (); <br/> break; <br/> default: <br/> return Super. oncontextitemselected (item); <br/>}< br/> video. requestfocus (); <br/> return true; <br/>}< br/>
/************** Main. XML *****************************/<br/> <? XML version = "1.0" encoding = "UTF-8"?> <Br/> <linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android" <br/> Android: Orientation = "vertical" <br/> Android: layout_width = "fill_parent" <br/> Android: layout_height = "fill_parent" <br/> <videoview Android: layout_height = "fill_parent" Android: layout_width = "fill_parent" Android: id = "@ + ID/videoview"> </videoview> <br/> </linearlayout> <br/> /************* ** strings. XML *********** * ***************/<Br/> <? XML version = "1.0" encoding = "UTF-8"?> <Br/> <resources> <br/> <string name = "open_3gp"> enable 3GP </string> <br/> <string name = "app_name"> videoplayer </ string> <br/> <string name = "shut_down"> close... </string> <br/> <string name = "open_mp4"> open MP4 </string> <br/> <string name = "open_avi"> open Avi </string> <br/> </resources> <br/>
It's just Java, but I'm still not familiar with it...
Okay, so much nonsense. Let's take a look at the 3GP playback process.
Mediaplayerservice or the stream layer above pvmf is not much said. These processes are described on the Internet and in books. (For example, <Android system principles and key points for development> ).
Reference: http://blog.csdn.net/wstarx/archive/2008/12/17/3541458.aspx
If you follow the steps described in fileformats above, the 3GP file format is not found ?!