code example
Public class mainactivity extends Activity{MediaPlayer Mediaplayer1,mediaplayer2;@Override protected void onCreate(Bundle savedinstancestate) {Super. OnCreate (Savedinstancestate); Setcontentview (R.layout.activity_main); MediaPlayer1 = Mediaplayer.create ( This, R.raw.shoot.mp3); Assetmanager asset = Getassets ();Try{Assetfiledescriptor asf = ASSET.OPENFD ("Shot.mp3"); MediaPlayer2 =NewMediaPlayer (); Mediaplayer2.setdatasource (Asf.getfiledescriptor ()); Mediaplayer2.prepare (); }Catch(Exception e) {E.printstacktrace (); } Findviewbyid (R.id.btnraw). Setonclicklistener (NewView.onclicklistener () {@Override Public void OnClick(View view) {Mediaplayer1.start (); } }); Findviewbyid (R.id.btnplay). Setonclicklistener (NewView.onclicklistener () {@Override Public void OnClick(View view) {Mediaplayer2.start (); } }); }}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Android Raw resources using raw and assert resources-android learning Journey (57)