Skip to content

Commit

Permalink
Re-enable CobaltMediaSession
Browse files Browse the repository at this point in the history
b/377019873
  • Loading branch information
Colin Liang committed Nov 7, 2024
1 parent 477c627 commit 975a283
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 30 deletions.
5 changes: 2 additions & 3 deletions cobalt/android/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ android_library("cobalt_apk_java") {
deps = [
":cobalt_java_resources",
"//base:base_java",
"//base:base_java",
"//base:process_launcher_java",
"//build/android:build_java",
"//components/embedder_support/android:view_java",
Expand All @@ -56,6 +55,7 @@ android_library("cobalt_apk_java") {
"//net/android:net_java",
"//third_party/android_deps:com_google_code_findbugs_jsr305_java",
"//third_party/androidx:androidx_annotation_annotation_java",
"//third_party/androidx:androidx_media_media_java",
"//ui/android:ui_java",
"//ui/android:ui_no_recycler_view_java",
"//url:gurl_java",
Expand All @@ -69,8 +69,7 @@ android_library("cobalt_apk_java") {
"apk/app/src/main/java/dev/cobalt/coat/CaptionSettings.java",
"apk/app/src/main/java/dev/cobalt/coat/CobaltActivity.java",
"apk/app/src/main/java/dev/cobalt/coat/CobaltHttpHelper.java",

# "apk/app/src/main/java/dev/cobalt/coat/CobaltMediaSession.java",
"apk/app/src/main/java/dev/cobalt/coat/CobaltMediaSession.java",
"apk/app/src/main/java/dev/cobalt/coat/CobaltService.java",
"apk/app/src/main/java/dev/cobalt/coat/CobaltSystemConfigChangeReceiver.java",
"apk/app/src/main/java/dev/cobalt/coat/CobaltTextToSpeechHelper.java",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public interface HostApplication {
private CobaltTextToSpeechHelper ttsHelper;
// TODO(cobalt): Re-enable these classes or remove if unnecessary.
private AudioOutputManager audioOutputManager;
// private CobaltMediaSession cobaltMediaSession;
private CobaltMediaSession cobaltMediaSession;
// private AudioPermissionRequester audioPermissionRequester;
private NetworkStatus networkStatus;
private ResourceOverlay resourceOverlay;
Expand Down Expand Up @@ -125,8 +125,8 @@ public StarboardBridge(
this.sysConfigChangeReceiver = new CobaltSystemConfigChangeReceiver(appContext, stopRequester);
this.ttsHelper = new CobaltTextToSpeechHelper(appContext);
this.audioOutputManager = new AudioOutputManager(appContext);
// this.cobaltMediaSession =
// new CobaltMediaSession(appContext, activityHolder, audioOutputManager, artworkDownloader);
this.cobaltMediaSession =
new CobaltMediaSession(appContext, activityHolder, audioOutputManager, artworkDownloader);
// this.audioPermissionRequester = new AudioPermissionRequester(appContext, activityHolder);
this.networkStatus = new NetworkStatus(appContext);
this.resourceOverlay = new ResourceOverlay(appContext);
Expand Down Expand Up @@ -190,7 +190,7 @@ protected void beforeStartOrResume() {
Log.i(TAG, "Prepare to resume");
// Bring our platform services to life before resuming so that they're ready to deal with
// whatever the web app wants to do with them as part of its start/resume logic.
// cobaltMediaSession.resume();
cobaltMediaSession.resume();
networkStatus.beforeStartOrResume();
for (CobaltService service : cobaltServices.values()) {
service.beforeStartOrResume();
Expand All @@ -206,7 +206,7 @@ protected void beforeSuspend() {
// We want the MediaSession to be deactivated immediately before suspending so that by the
// time, the launcher is visible our "Now Playing" card is already gone. Then Cobalt and
// the web app can take their time suspending after that.
// cobaltMediaSession.suspend();
cobaltMediaSession.suspend();
networkStatus.beforeSuspend();
for (CobaltService service : cobaltServices.values()) {
service.beforeSuspend();
Expand Down Expand Up @@ -615,18 +615,14 @@ void updateMediaSession(
MediaImage[] artwork,
long duration) {

// TODO(b/377019873): re-enable
Log.e(TAG, "MediaSession is disabled");
// cobaltMediaSession.updateMediaSession(
// playbackState, actions, positionMs, speed, title, artist, album, artwork, duration);
cobaltMediaSession.updateMediaSession(
playbackState, actions, positionMs, speed, title, artist, album, artwork, duration);
}

@SuppressWarnings("unused")
@UsedByNative
public void deactivateMediaSession() {
// TODO(b/377019873): re-enable
Log.e(TAG, "MediaSession is disabled");
// cobaltMediaSession.deactivateMediaSession();
cobaltMediaSession.deactivateMediaSession();
}

/** Returns string for kSbSystemPropertyUserAgentAuxField */
Expand Down Expand Up @@ -732,11 +728,9 @@ public int[] getSupportedHdrTypes() {
return hdrCapabilities.getSupportedHdrTypes();
}

// TODO(b/377019873): Re-enable MediaSession
/** Return the CobaltMediaSession. */
// public CobaltMediaSession cobaltMediaSession() {
// return cobaltMediaSession;
// }
public CobaltMediaSession cobaltMediaSession() {
return cobaltMediaSession;
}

public void registerCobaltService(CobaltService.Factory factory) {
cobaltServiceFactories.put(factory.getServiceName(), factory);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
import android.media.AudioTrack;
import android.os.Build;
import androidx.annotation.RequiresApi;
// TODO(b/377019873): Re-enable Mediasession
// import dev.cobalt.coat.CobaltMediaSession;
import dev.cobalt.coat.CobaltMediaSession;
import dev.cobalt.util.Log;
import dev.cobalt.util.UsedByNative;
import java.util.ArrayList;
Expand All @@ -36,9 +35,7 @@
import java.util.concurrent.atomic.AtomicBoolean;

/** Creates and destroys AudioTrackBridge and handles the volume change. */
// TODO(b/377019873): Re-enable Mediasession as below:
// public class AudioOutputManager implements CobaltMediaSession.UpdateVolumeListener {
public class AudioOutputManager {
public class AudioOutputManager implements CobaltMediaSession.UpdateVolumeListener {
private List<AudioTrackBridge> audioTrackBridgeList;
private Context context;

Expand All @@ -50,14 +47,12 @@ public AudioOutputManager(Context context) {
audioTrackBridgeList = new ArrayList<AudioTrackBridge>();
}

/* TODO(b/377019873): Re-enable MediaSession
@Override
public void onUpdateVolume(float gain) {
for (AudioTrackBridge audioTrackBridge : audioTrackBridgeList) {
audioTrackBridge.setVolume(gain);
}
}
*/

@SuppressWarnings("unused")
@UsedByNative
Expand Down
4 changes: 1 addition & 3 deletions starboard/android/shared/system_get_extensions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ const void* SbSystemGetExtension(const char* name) {
return starboard::android::shared::GetConfigurationApi();
}
if (strcmp(name, kCobaltExtensionMediaSessionName) == 0) {
// TODO(b/377019873): Re-enable
// return starboard::android::shared::GetMediaSessionApi();
return NULL;
return starboard::android::shared::GetMediaSessionApi();
}
if (strcmp(name, kCobaltExtensionGraphicsName) == 0) {
// TODO(b/377052944): Check if this is needed, likely can be
Expand Down

0 comments on commit 975a283

Please sign in to comment.