How to play Base 64 encoded audio in Android - android
I'm trying to play some base 64 encoded audio in Android, and I've followed various examples to come up with the following code:
MediaPlayer soundPlayer = new MediaPlayer();
try {
soundPlayer.setDataSource(audioData);
soundPlayer.setOnCompletionListener(new OnCompletionListener() {
#Override
public void onCompletion(MediaPlayer mp) {
mp.stop();
mp.release();
}
});
soundPlayer.prepare();
soundPlayer.setVolume(100f, 100f);
soundPlayer.setLooping(false);
soundPlayer.start();
}
catch (Exception e) {
.
.
.
}
When this code executes, I just get silence - and the following error:
08-24 11:38:58.555: W/System.err(18862): java.io.IOException: Prepare
failed.: status=0x1 08-24 11:38:58.555: W/System.err(18862): at
android.media.MediaPlayer.prepare(Native Method) 08-24 11:38:58.555:
W/System.err(18862): at
application.main.Application$27.run(Application.java:233)
Would appreciate if anyone can point out where I'm going wrong. The 'audioData' variable in question (which, if you manage to decode and play it, describes my frustration) is as follows:
data:application/octet-stream;base64,GkXfo59ChoEBQveBAULygQRC84EIQoKEd2VibUKHgQRChYECGFOAZwH/////////FUmpZpkq17GDD0JATYCGQ2hyb21lV0GGQ2hyb21lFlSua7+uvdeBAXPFh+lZ/IvV7yqDgQKGhkFfT1BVU2Oik09wdXNIZWFkAQEAAIC7AAAAAADhjbWERzuAAJ+BAWJkgSAfQ7Z1Af/////////ngQCjQZSBAACA+4O1bX7U7Fau4djaow6/qEcFOx2D6vgdTWqanSWTXXa4MzJRsP2c4GEeQwl5/cRiYFl3QmBVeh8n5mGhkgidhLFrDoCIMEJBptK5vggcJl5zwHJSDWDOFwrI/RRvrygpr+L+fHCQ8vnKQfn6W+U1MYhPc4u/xVkm4pp1qsZTyEXM3SQLnlOPNR5Lrp0q7lSyiezMrJ9JpcC3GBB4PrxIhyN09K7iyACAS3gPH1J3dmCt1JDNkJ/hpZRRU2mEPBC/ooXsqZ24Znqkr4XqmHfybYX0tEu5iTz7gngLbxiyPPEfcKYKpwAljaLLjOINVSna8jmkulRVNOIJ1edk2pGnwP5+FhU/5mia2w3sniEBjvBS5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xsvHXi2lhKjRpl8XzyjQn+K5DiJS+p9P8IEz6QoqPo6WELX76WPY9IXyJNgZ9kO7pFBncr7LBrQr4o1DnUVQlnFp/Flm0GWLH7GYCFw2Bbm6uiQsCp7sY7cVloFkmmgtN+4jtv75bdgDafsTZI90drCFYAVTHBKKfRjxi01E7EM15Hy/irSvXFxeV4gbMQ/2u9kA2GI/29WIzqQW+TOLgaA7lENLrVVQtUxf5Vlmv08oCL86A3u/9E59JYe5dZ7sthg=
Example Code of Playing Base64 encoded audio in Android :
public class MainActivity extends AppCompatActivity {
Button button;
String base64FormattedString="GkXfo59ChoEBQveBAULygQRC84EIQoKEd2VibUKHgQRChYECGFOAZwH/////////FUmpZpkq17GDD0JATYCGQ2hyb21lV0GGQ2hyb21lFlSua7+uvdeBAXPFh+lZ/IvV7yqDgQKGhkFfT1BVU2Oik09wdXNIZWFkAQEAAIC7AAAAAADhjbWERzuAAJ+BAWJkgSAfQ7Z1Af/////////ngQCjQZSBAACA+4O1bX7U7Fau4djaow6/qEcFOx2D6vgdTWqanSWTXXa4MzJRsP2c4GEeQwl5/cRiYFl3QmBVeh8n5mGhkgidhLFrDoCIMEJBptK5vggcJl5zwHJSDWDOFwrI/RRvrygpr+L+fHCQ8vnKQfn6W+U1MYhPc4u/xVkm4pp1qsZTyEXM3SQLnlOPNR5Lrp0q7lSyiezMrJ9JpcC3GBB4PrxIhyN09K7iyACAS3gPH1J3dmCt1JDNkJ/hpZRRU2mEPBC/ooXsqZ24Znqkr4XqmHfybYX0tEu5iTz7gngLbxiyPPEfcKYKpwAljaLLjOINVSna8jmkulRVNOIJ1edk2pGnwP5+FhU/5mia2w3sniEBjvBS5W2WiXOU40qYCG+0LY7+WmFFAovpUddWzC1Jv5T6HpmLELnSYojoC6QKC8ECn8m7y0L9EIoMGkDH04Fk6l359StgSGpqqp1BVhCiMHzebvOM4pRXDzLJdCsYi3WFQfWf+ojKKZixVh3iuDDaKJqhxio5xBmXH/SDTlwQedAL06NBeIEAPID7g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y/irSvXFxeV4gbMQ/2u9kA2GI/29WIzqQW+TOLgaA7lENLrVVQtUxf5Vlmv08oCL86A3u/9E59JYe5dZ7sthg=";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button=findViewById(R.id.btnId);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
playMedia();
}
});
}
public void playMedia() {
try{
String url = "data:audio/mp3;base64,"+base64FormattedString;
MediaPlayer mediaPlayer = new MediaPlayer();
try {
mediaPlayer.setDataSource(url);
mediaPlayer.prepareAsync();
mediaPlayer.setVolume(100f, 100f);
mediaPlayer.setLooping(false);
} catch (IllegalArgumentException e) {
Toast.makeText(getApplicationContext(), "You might not set the DataSource correctly!", Toast.LENGTH_LONG).show();
} catch (SecurityException e) {
Toast.makeText(getApplicationContext(), "You might not set the DataSource correctly!", Toast.LENGTH_LONG).show();
} catch (IllegalStateException e) {
Toast.makeText(getApplicationContext(), "You might not set the DataSource correctly!", Toast.LENGTH_LONG).show();
} catch (IOException e) {
e.printStackTrace();
}
mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer player) {
player.start();
}
});
mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
#Override
public void onCompletion(MediaPlayer mp) {
mp.stop();
mp.release();
}
});
}
catch(Exception e){
e.printStackTrace();
}
}
}
Also : AudioTrack is recommend to play a single audio resource for Java applications.
your error occurred because of the length of the base64 url limitation. media cannot prepare datasource for the long string. what I found base64 url for around 128 characters maybe work well. For long string you have to split string into pieces and fetch base64 url for small strings.
Related
Play audio from url one after other
I want to play/stream audio from url one after other automatically. here what I have tried: final String audioUrl[] = {"https://www.googleapis.com/storage/v1/b/ezconnectpoc/o/NV.wav?alt=media", "https://www.googleapis.com/storage/v1/b/ezconnectpoc/o/cqo.wav?alt=media"}; backtobackButton.setOnClickListener(new View.OnClickListener() { #Override public void onClick(View view) { try { mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); mediaPlayer.setDataSource(audioUrl[currentTrack]); mediaPlayer.prepareAsync(); mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { #Override public void onPrepared(MediaPlayer mp) { mediaPlayer.start(); } }); mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { #Override public void onCompletion(MediaPlayer mp) { try { Log.d("Current track",currentTrack+""); Log.d("audioUrl.length",audioUrl.length+""); if (currentTrack < audioUrl.length) { currentTrack++; mediaPlayer.setDataSource(audioUrl[currentTrack]); mediaPlayer.setOnCompletionListener(this); mediaPlayer.start(); } mediaPlayer.stop(); } catch (Exception e) { e.printStackTrace(); } } }); } catch (Exception e) { e.printStackTrace(); // make something } } }); My first audio url gets played when I click on backtoback named button but failed to play second audio from url.
changed this part of code mediaPlayer.reset(); mediaPlayer.setDataSource(audioUrl[currentTrack]); mediaPlayer.prepareAsync(); mediaPlayer.setOnCompletionListener(this); mediaPlayer.start(); currentTrack++; and worked.
android Media player not reading some mp3 url
i've created a playlist based on Media Player class. The thing is that it succeed in reading some mp3 url and it doesn't for another ones. For example here is a directory of mp3 i've uploaded but no one is working: http://rajaapp12.0fees.us/gbv3/ in the other hands an mp3 which work: http://mp3.mp3zik.com/music/Music-Rap/Casa%20Verde%202009/track%20(14).mp3 I don't think there is a problem with the code since it works already witch some url, but here is the most iportant part of it : public void beginLrcPlay(){ killMediaPlayer(); mPlayer = new MediaPlayer(); try { mPlayer.setDataSource(songEnCours.getSource_128()); mPlayer.setLooping(true); mPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { public void onPrepared(MediaPlayer mp) { mp.start(); if (mTimer == null) { mTimer = new Timer(); mTask = new LrcTask(); mTimer.scheduleAtFixedRate(mTask, 0, mPalyTimerDuration); } } }); mPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { public void onCompletion(MediaPlayer mp) { //fin musique ajouter action ! stopLrcPlay(); chantSuivant(); btnPlay.setImageResource(R.drawable.bg_selector_btn_play); } }); mPlayer.setOnBufferingUpdateListener(onBufferingUpdateListener); mPlayer.prepare(); mPlayer.start(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalStateException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
Android Media Player Replay Option
How can i replay a .mp3 in my app? I can't replay the mp3 using the start method Here is the code segment : mMediaPlayer = MediaPlayer.create(MainActivity.this, R.raw.splashsound); mMediaPlayer.setLooping(true); Button myButtonOne = (Button) findViewById(R.id.songon); myButtonOne.setOnClickListener(new OnClickListener() { #Override public void onClick(View v) { mMediaPlayer.start(); } }); Button myButtonTwo = (Button) findViewById(R.id.songoff); myButtonTwo.setOnClickListener(new OnClickListener() { #Override public void onClick(View v) { if(mMediaPlayer.isPlaying()){ //mMediaPlayer.stop(); mMediaPlayer.release(); mMediaPlayer = null; } } }); Can anyone please tell me what i am doing wrong here?
If you want to replay the mp3 why do release and set to null your media player? I guess that is your problem! Just stop and start it again without releasing your media player instance.
To replay mp3 track try this: private void playSong(int songIndex) { // Play song try { mp.reset(); mp.setDataSource(songsList.get(songIndex).get("songPath")); mp.prepare(); mp.start(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalStateException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } Or without calling reset(): mediaPlayer.setLooping(true);
Media Player called in state 0, error (-38,0)
I am currently trying to design a simple app that streams an internet radio station. I have the URL for the station and am setting up the Media Player like MediaPlayer mediaPlayer = new MediaPlayer(); try { mediaPlayer.setDataSource(URL); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (SecurityException e) { e.printStackTrace(); } catch (IllegalStateException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } try { mediaPlayer.prepare(); } catch (IllegalStateException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } mediaPlayer.start(); The program isn't crashing when emulated, but nothing is playing and I am get the following error: start called in state 0 and right below it is Error (-38,0) Does anyone know what this means? I've read a little about these state errors, but couldn't find anything that applies to my project.
You need to call mediaPlayer.start() in the onPrepared method by using a listener. You are getting this error because you are calling mediaPlayer.start() before it has reached the prepared state. Here is how you can do it : mp.setDataSource(url); mp.setOnPreparedListener(this); mp.prepareAsync(); public void onPrepared(MediaPlayer player) { player.start(); }
It seems like Error -38 means a state-exception (as the error-message indicates). For example if you call start(), before the song was ready, or when you call pause(), even if the song isn't playing at all. To fix this issue check the state of the mediaPlayer before calling the methods. For example: if(mediaPlayer.isPlaying()) { mediaPlayer.pause(); } Additionally, the MediaPlayer is sending event-messages. Even if you do not need the prepared-event (although it would be a good idea to not start the playback before this event was fired) you must set a callback-listener. This also holds true for the OnErrorListener, OnCompletionListener, OnPreparedListener and OnSeekCompletedListener (if you call the seek method). Listeners can be attached simply by mediaPlayer.setOnPreparedListener(new OnPreparedListener() { #Override public void onPrepared(MediaPlayer mp) { // Do something. For example: playButton.setEnabled(true); } });
I got this error when I was trying to get the current position (MediaPlayer.getCurrentPosition()) of media player when it wasn't in the prepared stated. I got around this by Keeping track of its state and only calling the getCurrentPosition() method after onPreparedListener is called.
This is my code,tested and working fine: package com.example.com.mak.mediaplayer; import android.media.MediaPlayer; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.app.Activity; public class MainActivity extends Activity { #Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); final MediaPlayer mpp = MediaPlayer.create(this, R.raw.red); //mp3 file in res/raw folder Button btnplay = (Button) findViewById(R.id.btnplay); //Play btnplay.setOnClickListener(new View.OnClickListener() { #Override public void onClick(View vone) { mpp.start(); } }); Button btnpause = (Button) findViewById(R.id.btnpause); //Pause btnpause.setOnClickListener(new View.OnClickListener() { #Override public void onClick(View vtwo) { if (mpp.isPlaying()) { mpp.pause(); mpp.seekTo(0); } } }); } }
I encountered the same issue few days ago. My audio MediaPlayer works fine on devices with high processing power, but for slow devices, the media player just did not play some time and from LogCat it had many complain about called in wrong state. So I resolved it by calling putting the call to start(), pause(),... in onPrepared() method of OnPreparedListener() as below: mediaPlayer.prepare(); mediaPlayer.setOnPreparedListener(new OnPreparedListener() { #Override public void onPrepared(MediaPlayer mp) { ........ mediaPlayer.start(); .... songControlBtn.setOnClickListener(new OnClickListener() { #Override public void onClick(View v) { if (mediaPlayer.isPlaying()) { mediaPlayer.pause(); } else { mediaPlayer.start(); } } }); mediaPlayer.setOnCompletionListener(new OnCompletionListener() { #Override public void onCompletion(MediaPlayer mp) { ............ } }); } }); Also try to release any media player that you do not need any more. For example, if you do not want to play the audio or video on background then you should call mediaPlayer.release() in onPause().
i tested below code. working fine public class test extends Activity implements OnErrorListener, OnPreparedListener { private MediaPlayer player; #Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); player = new MediaPlayer(); player.setAudioStreamType(AudioManager.STREAM_MUSIC); try { player.setDataSource("http://www.hubharp.com/web_sound/BachGavotte.mp3"); player.setOnErrorListener(this); player.setOnPreparedListener(this); player.prepareAsync(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalStateException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } #Override public void onDestroy() { super.onDestroy(); player.release(); player = null; } #Override public void onPrepared(MediaPlayer play) { play.start(); } #Override public boolean onError(MediaPlayer arg0, int arg1, int arg2) { return false; } }
Some times file are encoded in a way that Android can't decode. Even some mp4 files can not be played. Please try a different file format (.3gp are played most of the time) and see..
You get this message in the logs, because you do something that is not allowed in the current state of your MediaPlayer instance. Therefore you should always register an error handler to catch those things (as #tidbeck suggested). At first, I advice you to take a look at the documentation for the MediaPlayer class and get an understanding of what that with states means. See: http://developer.android.com/reference/android/media/MediaPlayer.html#StateDiagram Your mistake here could well be one of the common ones, the others wrote here, but in general, I would take a look at the documentation of what methods are valid to call in what state: http://developer.android.com/reference/android/media/MediaPlayer.html#Valid_and_Invalid_States In my example it was the method mediaPlayer.CurrentPosition, that I called while the media player was in a state, where it was not allowed to call this property.
above the picture,you can get the right way.
I solved both the errors (-19,0) and (-38,0) , by creating a new object of MediaPlayer every time before playing and releasing it after that. Before : void play(int resourceID) { if (getActivity() != null) { //Using the same object - Problem persists player = MediaPlayer.create(getActivity(), resourceID); player.setAudioStreamType(AudioManager.STREAM_MUSIC); player.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { #Override public void onCompletion(MediaPlayer mp) { player.release(); } }); player.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { #Override public void onPrepared(MediaPlayer mp) { mp.start(); } }); } } After: void play(int resourceID) { if (getActivity() != null) { //Problem Solved //Creating new MediaPlayer object every time and releasing it after completion final MediaPlayer player = MediaPlayer.create(getActivity(), resourceID); player.setAudioStreamType(AudioManager.STREAM_MUSIC); player.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { #Override public void onCompletion(MediaPlayer mp) { player.release(); } }); player.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { #Override public void onPrepared(MediaPlayer mp) { mp.start(); } }); } }
if(length>0) { mediaPlayer = new MediaPlayer(); Log.d("length",""+length); try { mediaPlayer.setDataSource(getApplication(),Uri.parse(uri)); } catch(IOException e) { e.printStackTrace(); } mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { #Override public void onPrepared(MediaPlayer mediaPlayer) { mediaPlayer.seekTo(length); mediaPlayer.start(); } }); mediaPlayer.prepareAsync();
It was every much frustrated. So, I got solution which works for me. try { if (mediaPlayer != null) { mediaPlayer.release(); mediaPlayer = null; } mediaPlayer = new MediaPlayer(); mediaPlayer.setDataSource(file.getAbsolutePath()); mediaPlayer.setAudioStreamType(AudioManager.STREAM_NOTIFICATION); mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { #Override public void onPrepared(MediaPlayer mediaPlayer) { mediaPlayer.start(); mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { #Override public void onCompletion(MediaPlayer mediaPlayer) { mediaPlayer.stop(); mediaPlayer.release(); mediaPlayer = null; } }); } }); mediaPlayer.prepare(); } catch (Exception e) { e.printStackTrace(); }
For me this worked mp.seekTo(0); mp.start();
I also got this error i tried with onPreparedListener but still got this error. Finally i got the solution that error is my fault because i forgot the internet permission in Android Manifest xml. :) <uses-permission android:name="android.permission.INTERNET" /> I used sample coding for mediaplayer. I used in StreamService.java onCreate method String url = "http://s17.myradiostream.com:11474/"; mediaPlayer = new MediaPlayer(); mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); mediaPlayer.setDataSource(url); mediaPlayer.prepare();
mp = new MediaPlayer(); AssetFileDescriptor afd = mContext.getAssets().openFd(fileName); mp.reset(); mp.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength()); mp.prepare(); mp.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { public void onPrepared(MediaPlayer mp) { mp.start(); } }); mp.prepareAsync();
I have change setAudioStreamType to setAudioAttributes; mediaPlayer.setAudioAttributes(AudioAttributes.Builder() .setFlags(AudioAttributes.FLAG_AUDIBILITY_ENFORCED) .setLegacyStreamType(AudioManager.STREAM_ALARM) .setUsage(AudioAttributes.USAGE_ALARM) .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) .build());
I am new in android programming and i had same error as this one. so i simply redefined the mp.createmediaPlayer = MediaPlayer.create(getApplicationContext(), Settings.System.DEFAULT_RINGTONE_URI). It may not the true way to do it but it worked fined for me: try { mp = MediaPlayer.create(getApplicationContext(), Settings.System.DEFAULT_RINGTONE_URI); } catch (Exception e) { e.printStackTrace(); } mp.start();
Android: Imagebutton, onclick play sound
I'm a noob trying to work something out and learn from it. I have two imagebuttons and when i click them I get a kind of "schick" sound rather than the sound files that i have in the /res/raw/ directory. This is my code: public void button_clicked1(View v) { text1.setText("1"+width); mp = MediaPlayer.create(GameScreen.this, R.raw.a); mp.start(); } public void button_clicked2(View v) { text1.setText("2"+height); mp = MediaPlayer.create(GameScreen.this, R.raw.b); mp.start(); } What am I doing wrong? Thanks! Ok, changed the above code to this: public void button_clicked1(View v) { text1.setText("1"+width); mp = MediaPlayer.create(GameScreen.this, R.raw.piano_a); try { mp .prepare(); } catch (IllegalStateException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } mp.start(); } public void button_clicked2(View v) { text1.setText("2"+height); mp = MediaPlayer.create(GameScreen.this, R.raw.piano_b); try { mp .prepare(); } catch (IllegalStateException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } mp.start(); } And it still does not work
EDIT: Try this: setVolumeControlStream(AudioManager.STREAM_MUSIC); in your main application code. This will tell the AudioManager that when your application has focus, the volume keys should adjust music volume (found that here). After that, make sure that your volume is up - it may just be playing the sounds with no volume.