Android Media (recording, playing music, playing video, etc)

Source: Internet
Author: User

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 ();}}

 

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.