Skip to content
This repository has been archived by the owner on Feb 26, 2023. It is now read-only.

Commit

Permalink
Android mediaplayer: Set pitch and speed on Marshmallow
Browse files Browse the repository at this point in the history
  • Loading branch information
mfietz committed Nov 2, 2015
1 parent 27d146a commit 33d20d5
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 12 deletions.
3 changes: 0 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ buildscript {
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.1'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}

Expand Down
8 changes: 4 additions & 4 deletions library/build.gradle
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 22
buildToolsVersion '22.0.1'
compileSdkVersion 23
buildToolsVersion '23.0.2'
defaultConfig {
minSdkVersion 9
targetSdkVersion 23
versionCode 1
versionName "1.0.2"
versionName "1.0.3"
}
buildTypes {
release {
minifyEnabled false
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
Expand Down
38 changes: 33 additions & 5 deletions library/src/main/java/org/antennapod/audio/AndroidAudioPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

import android.content.Context;
import android.media.MediaPlayer;
import android.media.PlaybackParams;
import android.net.Uri;
import android.os.Build;
import android.util.Log;

import java.io.IOException;
Expand Down Expand Up @@ -210,13 +212,23 @@ public AndroidAudioPlayer(org.antennapod.audio.MediaPlayer owningMediaPlayer, Co
public int getAudioSessionId() {
return mp.getAudioSessionId();
}

@Override
public boolean canSetPitch() {
return false;
if(Build.VERSION.SDK_INT >= 23) {
return true;
} else {
return false;
}
}

@Override
public boolean canSetSpeed() {
return false;
if(Build.VERSION.SDK_INT >= 23) {
return true;
} else {
return false;
}
}

@Override
Expand Down Expand Up @@ -404,18 +416,34 @@ public void setLooping(boolean loop) {

@Override
public void setPitchStepsAdjustment(float pitchSteps) {
// Can't!
if(Build.VERSION.SDK_INT < 23) {
return;
}
PlaybackParams params = mp.getPlaybackParams();
params.setPitch(params.getPitch() + pitchSteps);
mp.setPlaybackParams(params);
}

@Override
public void setPlaybackPitch(float f) {
// Can't!
Log.d(AMP_TAG, "setPlaybackPitch(" + f + ")");
if (Build.VERSION.SDK_INT < 23) {
return;
}
PlaybackParams params = mp.getPlaybackParams();
params.setPitch(f);
mp.setPlaybackParams(params);
}

@Override
public void setPlaybackSpeed(float f) {
// Can't!
Log.d(AMP_TAG, "setPlaybackSpeed(" + f + ")");
if (Build.VERSION.SDK_INT < 23) {
return;
}
PlaybackParams params = mp.getPlaybackParams();
params.setSpeed(f);
mp.setPlaybackParams(params);
}

@Override
Expand Down

0 comments on commit 33d20d5

Please sign in to comment.