Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions samples/powerplay/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />

<application
android:allowBackup="true"
Expand Down
12 changes: 12 additions & 0 deletions samples/powerplay/src/main/cpp/PowerPlayJNI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,18 @@ Java_com_google_oboe_samples_powerplay_engine_PowerPlayAudioPlayer_stopPlayingNa
player.triggerUp(index);
}

/**
* Native (JNI) implementation of PowerPlayAudioPlayer.updatePerformanceModeNative()
*/
JNIEXPORT void JNICALL
Java_com_google_oboe_samples_powerplay_engine_PowerPlayAudioPlayer_updatePerformanceModeNative(
JNIEnv *env,
jobject,
jobject mode) {
auto performanceMode = getPerformanceMode(env, mode);
player.updatePerformanceMode(performanceMode);
}

/**
* Native (JNI) implementation of PowerPlayAudioPlayer.setLoopingNative()
*/
Expand Down
27 changes: 11 additions & 16 deletions samples/powerplay/src/main/cpp/PowerPlayMultiPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,22 +132,7 @@ void PowerPlayMultiPlayer::triggerDown(int32_t index, oboe::PerformanceMode perf
return;
}

// If the performance mode has changed, we need to reopen the stream.
// Also reopen if the user has changed the MMAP policy (enabled/disabled) since the stream was opened.
if (performanceMode != mLastPerformanceMode ||
isMMapEnabled() != mLastMMapEnabled) {
teardownAudioStream();

// Attempt here to reopen the stream with the new performance mode.
const auto result = openStream(performanceMode);
if (!result) {
// Something went wrong and the stream could not be reopened.
__android_log_print(ANDROID_LOG_ERROR,
TAG,
"Failed to reopen stream with new performance mode");
return;
}
}
updatePerformanceMode(performanceMode);

// Assure previous sample is stopped and the play head is reset to zero, avoiding the
// currently playing index. Only allow the playback head to reset when the song has changed.
Expand Down Expand Up @@ -184,6 +169,16 @@ void PowerPlayMultiPlayer::triggerDown(int32_t index, oboe::PerformanceMode perf
}
}

void PowerPlayMultiPlayer::updatePerformanceMode(oboe::PerformanceMode performanceMode) {
if (performanceMode != mLastPerformanceMode ||
isMMapEnabled() != mLastMMapEnabled) {

__android_log_print(ANDROID_LOG_INFO, TAG, "updatePerformanceMode: Reopening stream");
teardownAudioStream();
openStream(performanceMode);
}
}

bool PowerPlayMultiPlayer::setMMapEnabled(bool enabled) {
auto result = oboe::OboeExtensions::setMMapEnabled(enabled);
return result == 0;
Expand Down
4 changes: 2 additions & 2 deletions samples/powerplay/src/main/cpp/PowerPlayMultiPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ class PowerPlayMultiPlayer : public iolib::SimpleMultiPlayer {

void triggerDown(int32_t index, oboe::PerformanceMode performanceMode) override;

void updatePerformanceMode(oboe::PerformanceMode performanceMode);

static bool setMMapEnabled(bool enabled);

static bool isMMapEnabled();

static bool isMMapSupported();

bool isMMapUsed();

int32_t getCurrentlyPlayingIndex();

int32_t setBufferSizeInFrames(int32_t bufferSizeInFrames);
Expand Down
Loading