java - Issue Preparing MediaPlayer to play custom file -
So basically everything works fine when I'm playing with the application in the audio / res / raw folder from the file However, when I want to select a file from a user, I have trouble, the user should have a data source for the media player set on the URI of the chosen file for the object. Then the player to start with the new data source and play it. My error comes when the game system is implemented. It says that I am asking to play in an illegal state (i had not already prepared the player), but it is definitely ready what is happening and how can I fix it?
Please help!
Invited method to choose a file:
Select Public Zero file () {intent to; Intent = new intent (); Intent.setAction (Intent.ACTION_GET_CONTENT); Intent.setType ("audio / mpeg"); StartActivityForResult (Intent.createChooser (intent, selected audio video path), 1); } Activity result method:
Public zero activity dissection on @Override (int requestcode, integer result code, intent data) {super.onActivityResult (requestCode, resultCode , Information); If (resultcode! = RESULT_CANCELED) {If (requestcode == 1 & amp; amp; resultcode == activity. RESULT_OK) {If ((data! = Null) & amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; Data; getData )! = Null)) {UserChosenFilePath = data .getData (); setSongToUserPick (); }}}} setSongToUserPick method:
public zero set SONGToUserPick () {stop (); CurrentAudioPath = userChosenFilePath; InitializePlayer (); Prevented = false; Play(); } Stop method:
public zero-stop () {isPlaying = false; Prevented = true; PlayPauseButton.setText ("Play"); Player.stop (); Player.release (); } Start the player method:
Public Zero initial player () {nowPlayingView.setText (filenameNumber .getBaseName (currentAudioPath.toString ()); Try {Player.setDataSource (thisContext, currentAudioPath); } Hold (illegal illegal concept | security access | illegalstateexception | iOException e) {e.printStackTrace (); } {Try Player.prepare ()}} (IllegalStateException | IOException e) {e.printStackTrace (); }} And finally, play method:
public zero play (if {iprpayer} {isPlaying = true; PlayPauseButton.setText ("Pause"); Player.start (); } And {System.out.println ("Aha broke."); }}
Use this if it helps you: < Pre> if (current audiopath! = Null) player = mediaplayer credits (this context, uri.from (current audio path.stustring ());
Comments
Post a Comment