Android - Equalizer usePreset not working (No change in sound effect) - android

I am working on streaming radio application. everything is working fine except the changing the equalizer effect does not affect sound.
Changing the equalizer effect by calling usePreset(preset) does not make any changes in the sound effects.
Even though there is no error, why usePreset does not change the sound effects.
I have tested in samsung galaxy sII with 4.0.3.
public void startPlayer() {
//
// Check whether we can acquire the audio focus
// to start the player
//
if (!requestAudioFocus()) {
return;
}
if (null != mAudioPlayer) {
if (mAudioPlayer.isPlaying()) {
mAudioPlayer.stop();
}
mAudioPlayer.reset();
} else {
mAudioPlayer = new MediaPlayer();
mAudioPlayer.reset();
}
try {
notifyProgressUpdate(PLAYER_INITIALIZING);
try {
mEqualizer = new Equalizer(0, mAudioPlayer.getAudioSessionId());
mEqualizer.setEnabled(true);
Log.d(TAG,
"Audio Session ID " + mAudioPlayer.getAudioSessionId()
+ "Equalizer " + mEqualizer + " Preset "
+ mEqualizer.getCurrentPreset());
} catch (Exception ex) {
mEqualizer = null;
}
mAudioPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mAudioPlayer.setDataSource(mCurrentTrack.getStreamURL());
//
// Add the Listener to track the player status
//
mAudioPlayer.setOnCompletionListener(this);
mAudioPlayer.setOnBufferingUpdateListener(this);
mAudioPlayer.setOnPreparedListener(this);
mAudioPlayer.setOnInfoListener(this);
mAudioPlayer.setOnErrorListener(this);
notifyProgressUpdate(PLAYER_BUFFERING);
mAudioPlayer.prepareAsync();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
//Get the available presets from the equalizer
public String[] getEqualizerPresets() {
String[] presets = null;
short noOfPresets = -1;
if (null != mEqualizer) {
noOfPresets = mEqualizer.getNumberOfPresets();
presets = new String[noOfPresets];
for (short index = 0; index < noOfPresets; index++) {
presets[index] = mEqualizer.getPresetName(index);
}
}
return presets;
}
//Set the user preferred presets
public void setEqualizerPreset(int position) {
if (null != mEqualizer) {
Log.d(TAG, "setting equlizer effects " + position);
Log.d(TAG, "Equalizer " + mEqualizer + " set Preset " + position);
mEqualizer.usePreset((short)position);
Log.d(TAG, "Equalizer " + mEqualizer + " current Preset "
+ mEqualizer.getCurrentPreset());
}
}
Appreciate your help to identify the issue.
EDIT
This issue is not resolved yet. i did not find any sample code which explain Equalizer Preset usage.
Any reference to code sample which uses Preset welcome.

this is a fully source code for equalizer, hope this will help you

I have the same problem. When I load it on emulator it produce an error that I don't really know why, it always says ...audiofx.Equalizer. and audiofx.AudioEffect. or something similar. But I have discovered that if you have other media player like n7player in my case, try to close it and try again your media player. In my case it works, but I think that it has to be one method to get some equalizer that is active.

Related

Error on some devices starting MediaRecorder start failed -19

I am trying to record video in my app, on my Nexus 5 and a ZTE this code works fine but on Samsumg Galaxy S2 and S3 fails with the exception "start failed -19" I'm a noob with the MediaRecorder, I only need a configuration that works on all cameras that record a .mp4 videofile file with normal quality.
try {
prCamera.unlock();
prMediaRecorder.setCamera(prCamera);
prMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
prMediaRecorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
prMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
prMediaRecorder.setVideoFrameRate(24);
prMediaRecorder.setVideoSize(720, 480);
prMediaRecorder.setVideoFrameRate(24);
prMediaRecorder.setVideoEncodingBitRate(3000000);
prMediaRecorder.setAudioEncodingBitRate(12200);
prMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
prMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
prMediaRecorder.setMaxDuration(cMaxRecordDurationInMs);
// Nombre del video de salida
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.ENGLISH).format(new Date());
nombreVideo = "video_" + timeStamp;
prRecordedFile = new File(cVideoFilePath + nombreVideo + ".mp4");
prMediaRecorder.setOutputFile(prRecordedFile.getPath());
prMediaRecorder.setPreviewDisplay(prSurfaceHolder.getSurface());
try {
prMediaRecorder.prepare();
// Fail on next line
prMediaRecorder.start();
} catch (IllegalStateException e) {
Log.d(tag, "IllegalStateException preparing MediaRecorder: " + e.getMessage());
timer.cancel();
cerrarCamara();
return false;
} catch (IOException e) {
Log.d(tag, "IOException preparing MediaRecorder: " + e.getMessage());
timer.cancel();
cerrarCamara();
return false;
} catch (Exception e) {
Log.d(tag, "Unknown exception preparing MediaRecorder: " + e.getMessage());
timer.cancel();
cerrarCamara();
return false;
}
prRecordInProcess = true;
Why you don't use
CamcorderProfile profile = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH);
I wasn't able to find the exact settings of this profile but I'm pretty sure the outputformat was mpeg4 and that is what you want...
I remember that most media recorder problems regard to wrong setted parameters. Try use this profile. It guarantees the highest available and working setup for the device. You can read further informations about this and other profiles which may fits your needs better here http://developer.android.com/reference/android/media/CamcorderProfile.html#QUALITY_HIGH

Android MediaPlayer.onInfo warning (952,0)

Im trying to do an application for android 4.2.2. It just have to play some muted videos in a endless loop inside an android videoview.
It works fine but, sometimes, I get a "cannot play this video" popup, despite I see the video playing under that popup. My app is supposed to run without any input method, so... ¿Is there any chance to avoid that popup? It appears to happen randomly, sometimes after 30-40 minutes, sometimes after some hours... Its just unpredictable.
I tried to debug it and, finally adding an onInfoListener, it seems like I got the error code (952). Besides, i didnt find any help with that error... Here is the code... Any tips/help would be VERY nice, so thank you in advance...
...
MediaPlayer.OnPreparedListener PreparedListener = new MediaPlayer.OnPreparedListener(){
#Override
public void onPrepared(MediaPlayer m) {
try {
if (m.isPlaying()) {
m.stop();
m.release();
m = new MediaPlayer();
m.setVolume(0f, 0f);
}
m.setLooping(false);
m.start();
} catch (Exception e) {
e.printStackTrace();
}
}
};
video.setOnPreparedListener(PreparedListener);
video.setOnInfoListener(new MediaPlayer.OnInfoListener() {
#Override
public boolean onInfo(MediaPlayer mp, int what, int extra) {
File file = new File(myRootDirectory.getAbsolutePath()+"/logVideo.txt");
SimpleDateFormat s = new SimpleDateFormat("dd-MM-yyyy//HH:mm:ss");
String format = s.format(new Date());
String text = format+": ("+what+","+extra+")\n";
if(what==952){
text = "!!!!!!!!!!\n"+text; //What is this code 952...??
}
FileOutputStream f = null;
try {
f = new FileOutputStream(file,true); //True = Append to file, false = Overwrite
PrintStream p = new PrintStream(f);
p.print(text);
p.flush();
p.close();
f.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
Log.i("Error", "******* File not found. Did you" +
" add a WRITE_EXTERNAL_STORAGE permission to the manifest?");
} catch (IOException e) {
e.printStackTrace();
}
Log.d("INFO LISTENER",what+" " + extra);
return false;
}
});
video.setVideoPath(nextVideo);
Maybe one of the standard "what" constants is misspelled? You might try to match against the known "what" codes (MEDIA_INFO_BAD_INTERLEAVING, etc).

Chromecast Android SDK: RemoteMediaPlayer always ends in IllegalStateException when trying to control

I'm trying to add media controls to my app but I can't get the RemoteMediaPlayer to send commands.
The video starts playing but then I can't control it.
This is the code I use:
RemoteMediaPlayer mRemoteMediaPlayer = new RemoteMediaPlayer();
try {
Cast.CastApi.setMessageReceivedCallbacks(apiClient, mRemoteMediaPlayer.getNamespace(), mRemoteMediaPlayer);
MediaMetadata mediaMetadata = new MediaMetadata(MediaMetadata.MEDIA_TYPE_MOVIE);
JSONObject jsonExtra = new JSONObject();
mediaMetadata.putString(MediaMetadata.KEY_TITLE, "My video");
if (mediaType != null) {
jsonExtra.put("type", mediaType);
}
if ("audio".equals(mediaType)) {
mimeType = "audio/mp3";
}
com.google.android.gms.cast.MediaInfo.Builder builder = new MediaInfo.Builder(getUrl()).setContentType(mimeType).setMetadata(mediaMetadata).setCustomData(jsonExtra);
builder.setStreamType(MediaInfo.STREAM_TYPE_BUFFERED);
MediaInfo mediaInfo = builder.build();
mRemoteMediaPlayer.load(apiClient, mediaInfo, true, inititalTime).setResultCallback(new ResultCallback<RemoteMediaPlayer.MediaChannelResult>() {
#Override
public void onResult(MediaChannelResult result) {
if (result.getStatus().isSuccess()) {
log(context, "Media loaded successfully");
}
}
});
Thread.sleep(5000);
mRemoteMediaPlayer.pause(apiClient);
} catch (IllegalStateException e) {
log(context, "Problem occurred with media during loading " + e);
} catch (IOException e) {
log(context, "Problem occurred with media during loading " + e);
} catch (JSONException e) {
log(context, "Problem occurred with media during loading " + e);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
You may notice that at the end I wait 5 seconds to make sure that the video is playing and then try to pause it.
This always results in an IllegalStateException with the message:
No current media session
Am I missing something?
I also notice that the ResultCallback is never called after the video starts playing. Maybe this is also related to the same issue I'm experiencing.
Thanks in advance.
It is not clear when you are running this piece of code. Do not set a sleep like you did; you have to register callbacks on mRemoteMediaPlayer to be notified when status or metadata changes on the remote player. When the status changed listener is called, get the updated status by calling mRemoteMediaPlayer.getMediaStatus().getPlayerState() and based on the status (whether it is playing, buffering, idle, paused), make the appropriate decision. In asynchronous systems, never use "sleep()", always hook into the callbacks.

Media Server died., Camera Died, Error 100

It is running & recording video 3 to 4 Mints. Later it stops the video recording.
At Log file it shows. Media Server died, Camera dies, Error 100.
Problem with videorecorder, CamcorderProfile settings.
I am using Android Emulator & Nexus 7 AVD,
Video settings are:
private void StartVideoRecording(Camera videoCamera){
videoRecorder = new MediaRecorder();
videoRecorder.setCamera(videoCamera);
videoRecorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
videoRecorder.setOutputFormat(cameraProfile.fileFormat); // look at ARTPWriter.cpp // videoRecorder.setOutputFormat(1); // look at ARTPWriter.cpp
videoRecorder.setVideoEncoder(cameraProfile.videoCodec);
videoRecorder.setVideoFrameRate(cameraProfile.videoFrameRate);
videoRecorder.setVideoSize(cameraProfile.videoFrameWidth, cameraProfile.videoFrameHeight);
videoRecorder.setVideoEncodingBitRate(cameraProfile.videoBitRate);
videoRecorder.setOutputFile("/mnt/sdcard/.Y3KVideo"); // File not used, but is needed for prepare to succeed.
videoRecorder.setPreviewDisplay(cameraViewSurfaceHolder.getSurface());
videoRecorder.setOrientationHint(90);
try {
videoRecorder.prepare();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
videoRecorder.start();
}
CamcorderProflie settings:
private void configureCameraProfile() {
cameraProfile = CamcorderProfile.get(CamcorderProfile.QUALITY_LOW);
cameraProfile.videoCodec = MediaRecorder.VideoEncoder.H264;
// cameraProfile.fileFormat = MediaRecorder.OutputFormat.THREE_GPP;
cameraProfile.fileFormat = 7; // RTP
cameraProfile.videoFrameWidth = 176; // QCIF PAL
cameraProfile.videoFrameHeight = 144;
cameraProfile.videoBitRate = 128000;
cameraProfile.videoFrameRate = 15; //15
Log.i(TAG, " bitrate=" + cameraProfile.videoBitRate + ",width=" + cameraProfile.videoFrameWidth + ",height=" + cameraProfile.videoFrameHeight);
}
Media Recorder May Work in Emulator.
But The settings You provided are Wrong.
please verify this link
http://developer.android.com/reference/android/media/MediaRecorder.html
and configure the settings as accordingly.

Android MediaPlayer not playing sound on some platforms

I'm currently developing an Android application that plays a sound to the user at various intervals. I have working code (included below) which functions exactly as expected on my Hero (running 2.2) and on the 1.6 emulator. However, it doesn't work on my friends Xperia x8 -- no sound is played. He has a notification tone set, which plays fine when he receives a text and so on.
private void prepareAudio(){
alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
mp = new MediaPlayer();
if(alert != null){
try {
mp.setDataSource(ctx, alert);
} catch (IllegalArgumentException e) {
Log.i("Prepare Audio", e.getMessage());
} catch (SecurityException e) {
Log.i("Prepare Audio", e.getMessage());
} catch (IllegalStateException e) {
Log.i("Prepare Audio", e.getMessage());
} catch (IOException e) {
Log.i("Prepare Audio", e.getMessage());
}
}
am = (AudioManager)ctx.getSystemService(Context.AUDIO_SERVICE);
}
private void notifyUser(){
if(alert != null){
if (am.getStreamVolume(AudioManager.STREAM_ALARM) != 0) {
mp.setAudioStreamType(AudioManager.STREAM_ALARM);
mp.setLooping(false);
try {
mp.prepare();
} catch (IllegalStateException e) {
Log.i("Notify User", e.getMessage());
} catch (IOException e) {
Log.i("Notify User", e.getMessage());
}
mp.start();
} else {
Log.i("Notify User", "Alarm volume zero");
}
} else {
Log.i("Notify User", "Uri is null");
}
long[] pattern = {0,200,300,600};
v.vibrate(pattern, -1);
}
PrepareAudio is called on initialising the class, and notifyUser every time we want to play the sound. The phone always vibrates when it should, so notifyUser is definitely being called.
The version my friend has installed uses e.printStackTrace rather than Log.i, so there's nothing being spat out in logcat. I'm going to try and get hold of his phone to update it to a version with Log.i, but in the meantime is there anything obviously wrong with the code that could cause such an intermittent problem?
Thanks,
So it turned out that updating my exception handling as listed in the original post appears to have fixed the problem.
If you're using the above code for anything, it's worth noting that sometimes e.getMessage() returns null, so rather than
Log.i("Notify User", e.getMessage());
use
Log.i("Notify User", e.getMessage() + "");
To avoid any nasty FCs when an exception is thrown.
Sorry for the incidentally unanswerable question!
Not sure, but older versions of Android had problems playing WAV files. Are these WAV files or MP3 files that you're trying to play?

Categories

Resources