-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Conversation
…to fix warnings about stream types. Also removed unused import.
mediaPlayer.setAudioAttributes(new AudioAttributes.Builder().setContentType( | ||
AudioAttributes.CONTENT_TYPE_MUSIC).build()); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ANewGalaxy @rkistner
@@ -94,23 +94,20 @@ public synchronized void playBeepSoundAndVibrate() { | |||
|
|||
public MediaPlayer playBeepSound() { | |||
MediaPlayer mediaPlayer = new MediaPlayer(); | |||
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed unused import
mp.reset(); | ||
mp.release(); |
There was a problem hiding this comment.
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
Thanks for the work - will get this out in the next release. |
Closes #586. I fixed the warnings I was getting related to MediaPlayer/BeepManager: