I have a soundboard uploaded on the android market. The app is doing pretty well in the market(50,000+ downloads), but the developer console reports that I have an error, and this is bothering me.
All crash reports come from only one device - Motorola Droid. I've looked at what the error actually is, and it happens when I call the start() method for the MediaPlayer class. I get the following:
java.lang.NullPointerException:
at com.meeg.soundit.Soundboard.playAudio(Soundboard.java:2517)
the code for the method playAudio is as follows and line 2517 is mp.start():
public void playAudio(int resid){
final MediaPlayer mp = MediaPlayer.create(this, resid);
mp.start();
mp.setOnCompletionListener(new OnCompletionListener() {
public void onCompletion(MediaPlayer arg0) {
mp.release();
}
});
}
Like I said, my soundboard has over 50,000 downloads, and it has 80 reports, all from the Motorola Droid. Is this something that I should ignore because 80 reports isn't much compared to how many people have used this, is there a problem with Moto Droid's and MediaPlayer, or is it just my code thats faulty?
This was a problem earlier on some builds that causes playback from resources to not work quite right. But you should fix your code to check for null and display appropriate message to the user.
Related
I used video capturing code using built-in camera in an application, but it reporting issues some of android phones like OnePlus phones. in other phones it works perfectly, can anyone help me to solve this issue, i tried many times but it didn't work, I'm sharing my code below..
Acutually it is shows only in device like one plus, I try to use built-in cam for to recording video, in my project, After we click button for to record video, it will redirected to the built-in cam in the device, in other devices it's working perfectly. but in one plus version11 , after we click the button for to record video it will not redirected to built-in cam, it is just stuck with the same page.. this is the issue
private void captureVideo() {
Intent VideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
if (VideoIntent.resolveActivity(getPackageManager()) != null) {
VideoIntent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
VideoIntent.putExtra("android.intent.extras.CAMERA_FACING", 1);
VideoIntent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, 3);
VideoIntent.putExtra(MediaStore.EXTRA_FINISH_ON_COMPLETION,true);
startActivityForResult(VideoIntent, VIDEO_REQUEST);
}
}
I made a small app to practice audio playing in android using MediaPlayer, the app works great but there is a small delay of 1 second after clicking the play button and it's noticeable, I noticed this happens only when starting the audio file, when paused it resumes immediately with no delay,I googled around and seen people suggests using SoundPool instead of MediaPlayer but SoundPool is recommended for short audio clips while my app is playing a full song, what's the cause of this delay? is there a fix or work around this issue?
Here's my code:
private MediaPlayer mMediaPlayer;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mMediaPlayer = MediaPlayer.create(this,R.raw.this_is_america);
Button btnPlay = findViewById(R.id.btnPlay);
Button btnPause = findViewById(R.id.btnPause);
Button btnStop = findViewById(R.id.btnStop);
btnPlay.setOnClickListener(this);
btnPause.setOnClickListener(this);
btnStop.setOnClickListener(this);
}
#Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btnPlay:
Toast.makeText(getApplicationContext(), "Playing song",
Toast.LENGTH_SHORT).show();
mMediaPlayer.start();
break;
case R.id.btnPause:
Toast.makeText(getApplicationContext(), "Pausing song",
Toast.LENGTH_SHORT).show();
mMediaPlayer.pause();
break;
case R.id.btnStop:
Toast.makeText(getApplicationContext(), "Song stopped",
Toast.LENGTH_SHORT).show();
mMediaPlayer.reset();
mMediaPlayer = MediaPlayer.create(this,R.raw.this_is_america);
break;
}
}
Update: Turned out to be the mp3 audio file had silent pause at the beginning , tried another song and it works fine no noticeable delays , thank you greeble31 for suggesting to check that.
Your song has a silent pause at the beginning ;)
As #Lucefer mentioned, the Android platform has some small unavoidable latency due to the implementation of the audio stack. Or, at least it did a few years back, not sure what the current state of affairs is. At any rate, this delay is generally far too small (~10ms) to notice at the beginning of an audio file; it has more to do with response times for apps that simulate musical instruments and the like.
There is an audio latency issue in the Android operating system. There is a few milliseconds delay while audio recording and audio playing. You can learn more about this by navigating below URLs. And this latency is related to the device types.
https://developer.android.com/ndk/guides/audio/audio-latency
https://source.android.com/devices/audio/latency/measurements
You can use a native toolkit or native program (C, C++ ndk base) to minimize this latency. But you cannot do reduce it to 0Seconds. only minimize the latency.
There is https://superpowered.com/superpowered-android-media-server . You can get support from this but as I know you need to pay for it. I didn't try it. Therefore i don't know how much it reduced the latency.
If you want to remove silent part from your mp3. you can use ffmpeg wrapper for it. Go to https://github.com/WritingMinds/ffmpeg-android-java link there is a working ffmpeg wrapper for Android. you can easily use it.
using FFMPEG with silencedetect to remove audio silence you can find relevant FFmpeg command for it by navigating to this.
in the wrapper you don't need ffmpeg part. You need to replace it from -y. You can get those details when navigate to that wrapper
I have an old Android app, targeted for SDK16, which played my own MP3 sounds loud and clear:
MediaPlayer mp;
setVolumeControlStream(AudioManager.STREAM_MUSIC);
if (mp != null) {
mp.reset();
mp.release();
}
mp = MediaPlayer.create(this, R.raw.red_click);
mp.setVolume(1.0f, 1.0f);
mp.start();
I haven't done any Android coding for a few years, and now I started to work on my old project again, but now targeted to SDK23. I didn't change my code from the one above. Now my sounds are still playing in the app, but really really quiet.
I tried to search for an answer but couldn't find any: what has changed in MP implementation from SDL16, and how should I play my files now such that I get the full volume for them?
I have a Android App I have developed, It has been created from a successful ios App that was released and works fine. On one device it works correctly, no errors and does not crash. However on another device (newer, newer version of Android, faster processor) it crashes. Here are the memory errors when it crashes.
The app is designed to take a picture and to then use that picture as the background for a canvas, then a screen shot is taken. I can go through this process once, but then if I repeat the process and take another picture, the application crashes on exit of the camera API for the second time. And displays these errors. The application is Developed in Eclipse using Phonegap and Jquery mobile. I am unsure which parts of my code I should post to help this problem, but please feel free to ask if you feel some may be relevant.
Any help is really appreciated.
Okay, if you review my post on why we run out of memory on PhoneGap Android apps:
http://simonmacdonald.blogspot.ca/2012/07/change-to-camera-code-in-phonegap-190.html
You may find some tips when you use the camera.getPicture() command. Other than that I'm currently working on fixing some of these Camera issues by bringing everything in house instead of firing a camera intent.
You can make such trick.... To set picture as background use...
public void setbg(){
String pathName = Environment.getExternalStorageState() + "scm_pic.jpg";
Resources res = getResources();
Bitmap bitmap = BitmapFactory.decodeFile(pathName);
BitmapDrawable bd = new BitmapDrawable(res, bitmap);
View view = findViewById(R.id.container);
view.setBackgroundDrawable(bd);
}
And then when you don't need this picture or want to #Override onPause methods or to switch another activity use...
private void unbindDrawables(View view) {
if (view.getBackground() != null) {
view.getBackground().setCallback(null);
}
if (view instanceof ViewGroup) {
for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) {
unbindDrawables(((ViewGroup) view).getChildAt(i));
}
((ViewGroup) view).removeAllViews();
}
}
To use it in #Override use for examole...
unbindDrawables(findViewById(R.id.container));
System.gc();
if you use camera means Destination type must in FILE_URL in android. because DATA_URI gives base64 string so it gives out of memory error sometime. First u get URL from camera then Convert base64 format using filesystem concepts...
In my application, I am trying to play a sound file in ogg format, stored in raw folder in res directory of my application. When I press the button that calls below function, it just freezes with the button pressed and does not respond. In the end, I have to terminate the application from Eclipse. Nothing about an error or exception in Logcat.
In debugging mode, it enters create function and never comes back. What am I doing wrong?
private void playbeep()
{
mPlayer = MediaPlayer.create(this, R.raw.beep);
mPlayer.start();
mPlayer.release();
}
You start and release the MediaPlayer at the same time. Try taking this out and see if it works.
mPlayer.release();
Also, check my post here to make sure you have the MediaPlayer set up correctly. If all else fails, try your audio file in a different format.