Skip to content

Instantly share code, notes, and snippets.

@adrian-bl
Created June 14, 2015 07:34
Show Gist options
  • Save adrian-bl/1135b6ae5d43bd2444be to your computer and use it in GitHub Desktop.
Save adrian-bl/1135b6ae5d43bd2444be to your computer and use it in GitHub Desktop.
diff --git a/src/ch/blinkenlights/android/vanilla/VanillaMediaPlayer.java b/src/ch/blinkenlights/android/vanilla/VanillaMediaPlayer.java
index dce062d..2faa693 100644
--- a/src/ch/blinkenlights/android/vanilla/VanillaMediaPlayer.java
+++ b/src/ch/blinkenlights/android/vanilla/VanillaMediaPlayer.java
@@ -22,6 +22,7 @@ import android.content.Context;
import android.content.Intent;
import android.media.MediaPlayer;
import android.media.audiofx.AudioEffect;
+import android.os.Build;
import java.io.IOException;
public class VanillaMediaPlayer extends MediaPlayer {
@@ -74,9 +75,13 @@ public class VanillaMediaPlayer extends MediaPlayer {
/**
* Sets the next media player data source
*/
- public void setNextMediaPlayer(VanillaMediaPlayer next) {
- super.setNextMediaPlayer(next);
- mHasNextMediaPlayer = (next != null);
+ public void setNextMediaPlayer(VanillaMediaPlayer next) throws UnsupportedOperationException {
+ if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
+ super.setNextMediaPlayer(next);
+ mHasNextMediaPlayer = (next != null);
+ } else {
+ throw new UnsupportedOperationException("setNextMediaPlayer() is not supported on this OS revision");
+ }
}
/**
@trophygeek
Copy link

I like this sanity check change.

I applied the patch and did a gradle build but it looks like you'll still need to add the @TargetApi tag to reassure it that you've addressed the problem. Lint isn't very smart about parsing the conditional check for Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN

/**
 * Sets the next media player data source
 */
@android.annotation.TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public void setNextMediaPlayer(VanillaMediaPlayer next) throws UnsupportedOperationException {

or, depending on your style preference

import android.annotation.TargetApi;
...
/**
 * Sets the next media player data source
 */
@TargetApi(16)
public void setNextMediaPlayer(VanillaMediaPlayer next) throws UnsupportedOperationException {

As a way to learn the code, I've been fixing Severity: Error lint issues on my branch. None of the fixes are actual bugs so far, just changes to make Lint happy.
vanilla-music/vanilla@master...trophygeek:Fix_lint_issues

@adrian-bl
Copy link
Author

Ok, thanks for letting me know this.
But then we could as well specify TargetApi(16) on triggerGaplessUpdate: This would make lint happy as well, wouldn't it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment