How to use FFmpegMediaPlayer ? (Windows|Android Studio) - android

I tried to use the lib prebuilt, but couldn't, I got error on - FFmpegMediaPlayer mp = new FFmpegMediaPlayer();
OR can somebody to recommend good Android MediaPlayer(minSdkVersion >=9) library for playing stream audio?

GIT URL for FFmpegMediaPlayer
have sample code :
FFmpegMediaPlayer mp = new FFmpegMediaPlayer();
mp.setOnPreparedListener(new FFmpegMediaPlayer.OnPreparedListener() {
#Override
public void onPrepared(FFmpegMediaPlayer mp) {
mp.start();
}
});
mp.setOnErrorListener(new FFmpegMediaPlayer.OnErrorListener() {
#Override
public boolean onError(FFmpegMediaPlayer mp, int what, int extra) {
mp.release();
return false;
}
});
try {
mp.setDataSource("<some path or URL>");
mp.prepareAsync();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

Related

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

BassBoost effect in android

I tried to implement bassboost effect in android..but there is no effect..I used the following code for bassboost effect;(I tried using global audio session id and i added permissions in manifest file)-->modify audio settings..
enter code here
BassBoost boost = new BassBoost(0,mp.getAudioSessionId());
boost.setEnabled(true);
boost.setStrength((Short)1000);
mp.attachAuxEffect(boost.getId());--->if i use this i'm getting(-38,0) or else no effect
mp.setSendLevel(1.0f);
I used below code for bass boost effect.got media player(-38,0) error..please resolve this issue..
enter code here
public class MainActivity extends Activity
{
MediaPlayer mediaplayer;
AssetFileDescriptor descriptor;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setVolumeControlStream(AudioManager.STREAM_MUSIC);
setContentView(R.layout.activity_main);
mediaplayer = new MediaPlayer();
mediaplayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
try {
descriptor = MainActivity.this.getAssets().openFd("Kalimba.mp3");
} catch (IOException e1) {
e1.printStackTrace();
}
try {
mediaplayer.setDataSource(descriptor.getFileDescriptor(),
descriptor.getStartOffset(), descriptor.getLength());
} catch (IllegalArgumentException e1) {
e1.printStackTrace();
} catch (IllegalStateException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
}
try {
descriptor.close();
} catch (IOException e1) {
e1.printStackTrace();
}
setUpBooster();
mediaplayer.setOnPreparedListener(new OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer mp) {
mp.start();
}
});
}
public void setUpBooster() {
BassBoost booster = new BassBoost(0,0);//-->tried with sessionid also
booster.setStrength((short) 1000);
booster.setEnabled(true);
mediaplayer.attachAuxEffect(booster.getId());
mediaplayer.setAuxEffectSendLevel(1.0f);
try {
mediaplayer.prepare();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
#Override
public void onBackPressed() {
super.onBackPressed();
}
}
error 38 means you are asking the MediaPlayer to do something when in the wrong state. You won't be able to fathom your error just from this.
And anytime you call setDataSource() on it you will need to prepare() it again. Think of it as loading the file, getting ready for playback.
Edit
You have already attached your bassboost with your mediaplayer when it created. So remove this mp.attachAuxEffect(boost.getId());

Media player not working in Android version >=4.0

I am developing a simple radio streaming application to play radio using a URL. This application is working in all the versions except for V>=4.0
Do anyone have any Idea over this.
initializeUIElements();
StartPlaying();
private void initializeUIElements() {
buttonPlay = (ImageView) findViewById(R.id.buttonPlay);
buttonPlay.setOnClickListener(this);
playSeekBar=(ProgressBar)findViewById(R.id.progressBar1);
}
private void startPlaying() {
initializeMediaPlayer();
player.setOnPreparedListener(new OnPreparedListener() {
public void onPrepared(MediaPlayer mp) {
Log.i("on prepared", "on prepared");
mp.start();
}
});
player.setOnErrorListener(new OnErrorListener(){
public boolean onError(MediaPlayer arg0, int arg1,
int arg2) {
Toast.makeText(getApplicationContext(),"An error happened while preparing radio",Toast.LENGTH_LONG).show();
player.reset();
initializeMediaPlayer();
return false;
}
});
private void initializeMediaPlayer() {
player = new MediaPlayer();
player.reset();
try {
player.setAudioStreamType(AudioManager.STREAM_MUSIC);
player.setDataSource("http://***************");
player.prepareAsync();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
catch(Exception e)
{
e.printStackTrace();
}
player.setOnBufferingUpdateListener(new OnBufferingUpdateListener() {
public void onBufferingUpdate(MediaPlayer mp, int percent) {
Log.i("percent", ""+percent);
if( (percent!=0)||(percent==100) )
{
playSeekBar.setVisibility(View.INVISIBLE);
buttonPlay.setVisibility(View.VISIBLE);
}
}
});
In Android version 4.0, It is giving an error as:
11-23 13:06:37.329: E/MediaPlayer(4011): Error (1,-2147483648)
and Player.bufferingUpdateListener() is not called. Here It is showing just that playseekbar revolving and revolving.. Please help on this.
It can be a problem with your particular device. Try running the same on 4.0 emulator.

getting Error for Audio Streaming in Android (using URL)

Want to do a audio streaming for a URL. The same URL is playing a live radio while running on the mobile browser. But while using MediaPlayer for android app there is no output. It gives the following error.
09-07 05:16:37.539: E/MediaPlayer(1265): error (1, -2147483648)
09-07 05:16:37.539: W/System.err(1265): java.io.IOException: Prepare failed.: status=0x1
My code sample is :
try {
Log.i("Audio Streaming", "start-->");
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.setDataSource(URL_OF_AUDIO);
mediaPlayer.prepare();
mediaPlayer.start();
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
make sure that URL which is passing is valid and check the androidmanifest whether it is having the access permission.
use onprepared listener to start the video to avoid some unwanted exceptions.
try this one it works 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;
}
}

MediaPlayer error android

I have an activity which has a series of buttons which when pressed should play an audio file. I have been trying to implement this using MediaPlayer however I cant get it to work.
Here is the code I have been trying:
final MediaPlayer mp = new MediaPlayer();
Button ger1play = (Button) findViewById(R.id.ger1play);ger1play.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
mp.setDataSource(this, R.raw.greet_1);
mp.prepare();
mp.start();
}
});
The setDateSource method doesnt seem to work, can anyone tell me where I am going wrong?
I would like to then set the mediaPlayer to the relevant audio file based on which button is pressed, is this possible?
Updated
final MediaPlayer mp = new MediaPlayer();
Button ger1play = (Button) findViewById(R.id.ger1play);ger1play.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
try {
Uri myUri = Uri.parse(R.raw.greet_1);
mp.setDataSource(GreetingsLesson.this, R.raw.greet_1);
mp.prepare();
mp.start();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
});
try this:
final MediaPlayer mp = new MediaPlayer();
Button ger1play = (Button) findViewById(R.id.ger1play);ger1play.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
try {
mp.setDataSource(CurrentActivity.this, R.raw.greet_1);
mp.prepare();
mp.start();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
});
Ifyou want to send the media player object with one of the files fromapplication raw resources or from application assets files you can dothat as follows:
try {
AssetFileDescriptor fd = getResources().openRawResouceFd(R.raw.greet_1);
mp.setDataSource(fd.getFileDescriptor(), fd.getStartOffset(), fd.getLength());
mp.start();
fd.close();
} catch (IllegalArgumentException e) {
// handle exception
} catch (IllegalStateException e) {
// handle exception
} catch (IOException e) {
// handle exception
}
Why not just use
mp = MediaPlayer.create(this, R.raw.greet_1);
Then you don't need the prepare or start.
Are you running this in an emulator? If so check your AVD manager has under hardware, the property "Audio playback support | yes" added

Categories

Resources