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 = "http://schemas.android.com/apk/res/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 android.net. uri; import android. OS. bundle; import android. support. v7.app. 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 );}}