Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing MediaPlayer warnings; #587

Merged
merged 3 commits into from
Feb 12, 2021
Merged

Conversation

ANewGalaxy
Copy link
Contributor

@ANewGalaxy ANewGalaxy commented Dec 12, 2020

Closes #586. I fixed the warnings I was getting related to MediaPlayer/BeepManager:

W/MediaPlayer: Use of stream types is deprecated for operations other than volume control
W/MediaPlayer: mediaplayer went away with unhandled events

Comment on lines +97 to +98
mediaPlayer.setAudioAttributes(new AudioAttributes.Builder().setContentType(
AudioAttributes.CONTENT_TYPE_MUSIC).build());
Copy link
Contributor Author

@ANewGalaxy ANewGalaxy Dec 12, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixes warning: W/MediaPlayer: Use of stream types is deprecated for operations other than volume control

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is causing crashes in Android 4 devices(4.4.2 and 4.4.4).
AudioAttributes was added in API level 21.

StackTrace:

Fatal Exception: java.lang.NoClassDefFoundError: android.media.AudioAttributes$Builder
       at com.google.zxing.client.android.BeepManager.playBeepSound(BeepManager.java:97)
       at com.google.zxing.client.android.BeepManager.playBeepSoundAndVibrate(BeepManager.java:84)
       at com.journeyapps.barcodescanner.CaptureManager$1.barcodeResult(CaptureManager.java:80)
       at com.journeyapps.barcodescanner.DecoratedBarcodeView$WrappedCallback.barcodeResult(DecoratedBarcodeView.java:50)
       at com.journeyapps.barcodescanner.BarcodeView$1.handleMessage(BarcodeView.java:52)
       at android.os.Handler.dispatchMessage(Handler.java:98)
       at android.os.Looper.loop(Looper.java:136)
       at android.app.ActivityThread.main(ActivityThread.java:5584)
       at java.lang.reflect.Method.invokeNative(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:515)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
       at dalvik.system.NativeStart.main(NativeStart.java)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -94,23 +94,20 @@ public synchronized void playBeepSoundAndVibrate() {

public MediaPlayer playBeepSound() {
MediaPlayer mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
Copy link
Contributor Author

@ANewGalaxy ANewGalaxy Dec 12, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed this line since it is a deprecated method. Replaced with setAudioAttributes method call.

import android.media.AudioManager;
import android.media.MediaPlayer;
import android.os.Vibrator;
import android.util.Log;

import java.io.Closeable;
Copy link
Contributor Author

@ANewGalaxy ANewGalaxy Dec 12, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed unused import

Comment on lines +101 to +102
mp.reset();
mp.release();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling reset before release should fix the following warning: W/MediaPlayer: mediaplayer went away with unhandled events

@rkistner
Copy link
Member

Thanks for the work - will get this out in the next release.

@rkistner rkistner merged commit 73093b9 into journeyapps:master Feb 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Getting warnings from MediaPlayer
3 participants