Android player MP3 and android player mp3

Source: Internet
Author: User

Android player MP3 and android player mp3

<? Xml version = "1.0" encoding = "UTF-8"?> <! -- Define the current layout of the basic LinearLayout --> <LinearLayout xmlns: android = "" android: layout_width = "fill_parent" android: layout_height = "fill_parent" android: orientation = "vertical"> <! -- Define the display control that prompts you to play mp3 videos --> <TextView android: id = "@ + id/TV" android: layout_width = "match_parent" android: layout_height = "wrap_content" android: hint = "click to play/sdcard/1.mp3 file"/> <! -- Define the control for clicking the playback sound Button --> <Button android: id = "@ + id/Btn" android: layout_width = "match_parent" android: layout_height = "wrap_content" android: text = "Playing Sound"/> </LinearLayout>
Package com. example. yanlei. yl2; import android. content. intent; import uri; import android. OS. bundle; import android. support. appCompatActivity; import android. view. view; import android. view. view. onClickListener; import android. widget. button; import android. widget. textView; public class MainActivity extends AppCompatActivity {// specifies the private Button btn of the Button control that defines the playback sound in the layout. // defines the private TextView TV control of the display label; @ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); // set the layout file of the current Activity to activity_main setContentView (R. layout. activity_main); // obtain the control object findView () in the browser; // set the object listener setListener ();} private void setListener () {// set the btn click listener btn. setOnClickListener (new OnClickListener () {@ Override public void onClick (View v) {// defines the intent object and sets the action attribute to Intent. ACTION_VIEW Intent it = new Intent (Intent. ACTION_VIEW); // defines the uri Uri of the song.mp3 file under sdcard= uri. parse ("file: // sdcard/1.mp3"); // not a memory card // set the intent data type to audio/mp3, in this way, you can start the system program to open the mp3 file it. setDataAndType (uri, "audio/mp3"); // use intent to open activity startActivity (it) ;});} private void findView () {// get the object btn = (Button) findViewById (R. id. btn); // get the EditText object TV = (TextView) findViewById (R. id. TV );}}


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: 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.