Android Media (recording, playing music, playing video, etc)
/*** Recording ** @ param incomingNumber */public void startRecorder (String incomingNumber) {// 1. create a recorder instance recorder = new MediaRecorder (); // 2. set the path of the data source (VOICE_CALL simulator and foreign mobile phones do not support) recorder. setAudioSource (MediaRecorder. audioSource. MIC); // 3. set the output file format recorder. setOutputFormat (MediaRecorder. outputFormat. THREE_GPP); // 4. set the name of the saved file recorder. setOutputFile ("/sdcard/" + incomingNumber + ". 3gp "); // 5. set the audio encoding format recorder. set AudioEncoder (MediaRecorder. audioEncoder. AMR_NB); // 6. prepare to start recording try {recorder. prepare ();} catch (IllegalStateException e) {// TODO Auto-generated catch block e. printStackTrace ();} catch (IOException e) {// TODO Auto-generated catch block e. printStackTrace ();} recorder. start ();}/*** play music * @ param incomingNumber */public void play (View view) {try {player = new MediaPlayer (); player. reset (); p Layer. setDataSource ("http://tsmusic24.tc.qq.com/4833285.mp3"); // player. prepare (); // prepare for synchronization. If not, wait until preparation (asynchronous preparation). player. prepareAsync (); // asynchronous preparation. If you are not prepared, the following error occurs: pb. setVisibility (View. VISIBLE); // call player when ready. setOnPreparedListener (new OnPreparedListener () {@ Override public void onPrepared (MediaPlayer mp) {// TODO Auto-generated method stub player. start (); pb. setVisibility (View. INVISIBLE) ;}}); // player. release (); // If release is called, the resource is released. You need to use it again next time.} catch (Exception e) {// TODO Auto-generated catch block e. printStackTrace ();}}