Android Studio : MediaPlayer setDataSource URL not playing music - android

Opening app without any error. But can't play music. But can play music from local machine. Internet connection is fine.
I have enabled internet permission in AndroidManiFest.xml
<uses-permission android:name="android.permission.INTERNET" />
I have enabled http permission.
android:usesCleartextTraffic="true"
MediaPlayer mediaPlayer = new MediaPlayer();
try {
mediaPlayer.setDataSource("http://penguinradio.dominican.edu/Sound%20FX%20Collection/Motorbike.mp3");
} catch (IOException e) {
e.printStackTrace();
}
mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer mP) {
Toast.makeText(MainActivity.this, "Ready to Play", Toast.LENGTH_SHORT).show();
mP.start();
}
});
mediaPlayer.prepareAsync();
Full Code:
https://paste.ubuntu.com/p/dsjbg7YMNn/

I have tested your code and sometimes it works, sometimes it doesn't. If you search on Stack Overflow you will find plenty of similar problems.
You have 2 options:
Migrate to ExoPlayer2 which is far superior that MediaPlayer.
It doesn't work to play the sound in OnPreparedListener, but you can play it on button click, after it's prepared:
public class MainActivity extends AppCompatActivity {
private Button streamButton;
private boolean isPrepared = false;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MediaPlayer mediaPlayer = new MediaPlayer();
try {
mediaPlayer.setDataSource("http://penguinradio.dominican.edu/Sound%20FX%20Collection/Motorbike.mp3");
} catch (IOException e) {
e.printStackTrace();
}
mediaPlayer.setOnPreparedListener(mp -> {
Toast.makeText(MainActivity.this, "Ready to Play", Toast.LENGTH_SHORT).show();
isPrepared = true;
streamButton.setVisibility(View.VISIBLE);
});
mediaPlayer.setOnCompletionListener(mp -> {
mp.release();
isPrepared = false;
streamButton.setVisibility(View.INVISIBLE);
});
mediaPlayer.prepareAsync();
streamButton = findViewById(R.id.streamButton);
streamButton.setOnClickListener(v -> {
if (isPrepared) {
mediaPlayer.start();
}
});
}
}

try this:
if(mediaPlayer != null ){
if (mediaPlayer.isPlaying()){mediaPlayer.stop();}
mediaPlayer.reset(); //this line is important!
String path = File.separator + "sdcard" + File.separator + utilsFields.repoDirRoot + File.separator + media.mp4;
try {
mediaPlayer.setDataSource(path);
}catch (Exception ignored){}
try {
mediaPlayer.prepare();
}catch (Exception ignored){}
mediaPlayer.start();
}

Related

How to play Base 64 encoded audio in 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/xVkm4pp1qsZTyEXM3SQLnlOPNR5Lrp0q7lSyiezMrJ9JpcC3GBB4PrxIhyN09K7iyACAS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XhtGG5XxmYWJwpDiXdQaX5fFIz65nxFAzxRxMg7KezqypulXxSiLdSulY2x1w5gTTLxVWztQviIYknGsoJhq47BN3V0XMSsksLJjipxT7TCqsNH0JazomASa4GZMbwA8cPN+fvlBb+1qmcbntdkqxsvHXi2lhKjRpl8XzyjQn+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+WmFFAovpUddWzC1Jv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Ez6QoqPo6WELX76WPY9IXyJNgZ9kO7pFBncr7LBrQr4o1DnUVQlnFp/Flm0GWLH7GYCFw2Bbm6uiQsCp7sY7cVloFkmmgtN+4jtv75bdgDafsTZI90drCFYAVTHBKKfRjxi01E7EM15Hy/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.

NullPointerException in MediaPlayer after pressing the home button and reopening the app

This is my code, I want to keep music playing when the app is in background. And I want to be able to pause it when I re-open the app. The music should play in the background, but for some reason media player returns null pointer when I re-open it. So, when I pause it, it crashes.
public void play(View view) {
if (status) {
status = false;
requestRecordAudioPermission();//audio permission
startPlay();//start mediaplayer
} else {
status = true;
mediaPlayer.pause();
}
}
public void startPlay() {
mediaPlayer = new MediaPlayer();
try {
mediaPlayer.setDataSource(URL_LINK);
mediaPlayer.prepare();
} catch (IOException e) {
e.printStackTrace();
Toast.makeText(HomeActivity.this, "CAN'T PLAY!",Toast.LENGTH_LONG).show();
}
mediaPlayer.start();
}
Why Media Player returns null after pressing the home button and reopening the app?
Thanks for help
If you are streaming audio from an url then try to load the Media Player asynchronously.
String url = "YOUR_URL";
MediaPlayer myMediaPlayer = new MediaPlayer();
myMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
try {
myMediaPlayer.setDataSource(url);
myMediaPlayer.prepareAsync();
} catch (IOException e) {
Toast.makeText(this, "mp3 not found", Toast.LENGTH_SHORT).show();
}
myMediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer player) {
player.start();
}
});

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();
}
}

Working with MP3 sound in Processing for Android ( need to stop )

I am developing an app for Android devices using Processing 2.0, now I have playMP3(); function but need to stop the sound using stopMP3();. I tried everything but what is the best way to load an mp3 and play/stop using processing?, snd.stop(); within the stopMP3 function does not work...
import android.media.*;
import android.content.res.*;
...
MediaPlayer snd;
...
void setup()
{
MediaPlayer snd = new MediaPlayer();
}
...
void playMP3()
{
try {
AssetManager assets = this.getAssets();
AssetFileDescriptor fd = assets.openFd("loop1.mp3");
snd.setDataSource(fd.getFileDescriptor(), fd.getStartOffset(), fd.getLength());
snd.prepare();
snd.start();
snd.setLooping(true);
}
catch (IllegalArgumentException e) {
e.printStackTrace();
}
catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
void stopMP3(){
????
}
this is a simple sample for media player
private MediaPlayer m_Player;
//Start Play Function
private void startPlaying() {
m_Player = new MediaPlayer();
m_Player.setOnCompletionListener(onComplete);
try {
if(m_Player.isPlaying())
stopPlaying();
m_Player.setDataSource(m_FileName);
m_Player.prepare();
m_Player.start();
} catch (IOException e) {
}
}
//Stop Play Function
private void stopPlaying() {
m_Player.stop();
m_Player.reset();
m_Player = null;
}
//and this is onComplete Listener
MediaPlayer.OnCompletionListener onComplete = new OnCompletionListener()
{
#Override
public void onCompletion(MediaPlayer mp)
{
stopPlaying();
}
};
i hope it's helping you

Setting an array of songs using MediaPlayer

I have 5 songs which i need to play one after the other, and it must loop from the first song after finishing the 5th song.
How do I use the MediaPlayer to achieve this?
public class MediaPlayerExample extends Activity implements MediaPlayer.OnCompletionListener {
int [] songs;
MediaPlayer mediaPlayer;
int current_index = 0;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
songs= new int[] {R.raw.song1,R.raw.song2,R.raw.song3,R.raw.song4};
mediaPlayer = MediaPlayer.create(this, songs[0]);
mediaPlayer.setOnCompletionListener(this);
mediaPlayer.start();
}
#Override
public void onCompletion(MediaPlayer mp) {
play();
}
private void play()
{
current_index = (current_index +1)% 4;
AssetFileDescriptor afd = this.getResources().openRawResourceFd(songs[current_index]);
try
{
mediaPlayer.reset();
mediaPlayer.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getDeclaredLength());
mediaPlayer.prepare();
mediaPlayer.start();
afd.close();
}
catch (IllegalArgumentException e)
{
Log.e(TAG, "Unable to play audio queue do to exception: " + e.getMessage(), e);
}
catch (IllegalStateException e)
{
Log.e(TAG, "Unable to play audio queue do to exception: " + e.getMessage(), e);
}
catch (IOException e)
{
Log.e(TAG, "Unable to play audio queue do to exception: " + e.getMessage(), e);
}
}
}
Simple:
int[] songs = new int[]{R.raw.ab_hai_hamari_bari, R.raw.ab_khel_jamay_ga, R.raw.ab_khel_ke_dikha_psl_official_song, R.raw.chakka_choka_islamabad_united, R.raw.dil_dil_pakistan_junaid, R.raw.duniya_se_aagay, R.raw.hai_jazba_junoon_tho_himmat_na_haar, R.raw.hum_hain_pakistani_junaid, R.raw.jeet_ki_lagan, R.raw.jeetay_ga_pakistan_dedicate, R.raw.josh_e_junoon_pakistan_cricket, R.raw.karachi_kings_official, R.raw.lahore_qalandar_official, R.raw.multan_sultan_official, R.raw.peshawar_zalmi, R.raw.quetta_gladiator, R.raw.stand_up_for_the_champions};
you need to use CountDownTimer for this. CountDown timer has give you facility to do this one by one ::
MediaPlayer mp_xmPlayer2 = new MediaPlayer();
mp_xmPlayer2 = MediaPlayer.create(this, R.raw.bg_music_wav);
for(int i=0;i<5;i++)
{
CountDownTimer cntr_aCounter = new CountDownTimer(3000, 1000) {
public void onTick(long millisUntilFinished) {
mp_xmPlayer2.start();
}
public void onFinish() {
//change music name
}
};
cntr_aCounter.start();
}

Categories

Resources