android MediaPlayer setDataSource not grabbing a playable file -
Well, the problem I have to get the stream to play other websites) with your localhost server (and raw MP3 files Is happening My code works for the site, which is annotated so I think it has something to do with the server and Java code
public class main activity provides Akshnbrektiviti {// Static final string enshor = "http://www.hrupin.com/wp-content/uploads/mp3/testsong_20_sec.mp3"; Fixed final string ANCHOR = "http://spintro.ddns.net/Random%20Access%20Memories/07%20-%20Touch.mp3"; @ Override Protected Zero (Bundle Saved Instantstate) {Super. NET (Saved Instantstate); SetContentView (R.layout.activity_main); Media Player MP = new Media Player (); Mp.setVolume (1, 1); Try {Mp.setDataSource (ANCHOR); Mp.prepareAsync (); } Hold (exception e) {e.printStackTrace (); } MpksetOnPreparedListener (New MediaPlayer.OnPreparedListener () {@Override public void onPrepared (MediaPlayer mp) {Toast.makeText (MainActivity.this, "Ready", Toast.LENGTH_LONG) .show (); mp.start ();} }); } @ Override Public Boolean On Crate Option Menu (Menu Menu) {// Enhancing Menu; It adds the item to the Action Bar if it exists GetMenuInflater (). Fluo (R. menu menu, menu); Back true; } @ Override Public Boolean On Option Itam Select (menu item) {// Handle action bar item here clicks the action bar will automatically click on the Home / Up button, so long as you // in AndroidManifest.xml Specify basic activity. Int id = item.getItemId (); If (id == R.id.action_settings) {return true; } Return Super.Options item selected (item); }}
to play
Refer to the code below the music file, my res / raw folder contains options_music.wav music file. For your URL, make sure that you have this properly encoded and accessible URL from your mobile.
// Play Music MediaPlayer mp = new MediaPlayer (); Property file descriptor descriptor; Try {discriptor = getAssets (). OpenFd ("options_music.wav"); Mp.setDataSource (descriptor.getFileDescriptor (), descriptor.getStartOffset (), descriptor.getLength ()); Descriptor.close (); Mp.prepare (); Mp.start (); mp.setOnCompletionListener (New OnCompletionListener () {@Override public void onCompletion (MediaPlayer mp) {//Log.e("Music "," music all ........ "); mp.start ();} }); } Hold (exception e) {log. ("Erratic", "Cant Music File" + e); }
Comments
Post a Comment