MediaSession2: Initial commit of MediaBrowser2
Test: Run all MediaComponents tests once Change-Id: I284806ff97da4ba53d7e4de9a39864f70f69a942
This commit is contained in:
@@ -46,6 +46,11 @@ interface IMediaSession2 {
|
||||
|
||||
PlaybackState getPlaybackState();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Get browser service specific
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////
|
||||
oneway void getBrowserRoot(IMediaSession2Callback callback, in Bundle rootHints);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Callbacks -- remove them
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
69
media/java/android/media/MediaBrowser2.java
Normal file
69
media/java/android/media/MediaBrowser2.java
Normal file
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright 2018 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package android.media;
|
||||
|
||||
import android.annotation.Nullable;
|
||||
import android.content.Context;
|
||||
import android.media.update.ApiLoader;
|
||||
import android.media.update.MediaBrowser2Provider;
|
||||
import android.os.Bundle;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
/**
|
||||
* Browses media content offered by a {@link MediaLibraryService2}.
|
||||
* @hide
|
||||
*/
|
||||
public class MediaBrowser2 extends MediaController2 {
|
||||
// Equals to the ((MediaBrowser2Provider) getProvider())
|
||||
private final MediaBrowser2Provider mProvider;
|
||||
|
||||
/**
|
||||
* Callback to listen events from {@link MediaLibraryService2}.
|
||||
*/
|
||||
public abstract static class BrowserCallback extends MediaController2.ControllerCallback {
|
||||
/**
|
||||
* Called with the result of {@link #getBrowserRoot(Bundle)}.
|
||||
* <p>
|
||||
* {@code rootMediaId} and {@code rootExtra} can be {@code null} if the browser root isn't
|
||||
* available.
|
||||
*
|
||||
* @param rootHints rootHints that you previously requested.
|
||||
* @param rootMediaId media id of the browser root. Can be {@code null}
|
||||
* @param rootExtra extra of the browser root. Can be {@code null}
|
||||
*/
|
||||
public abstract void onGetRootResult(Bundle rootHints, @Nullable String rootMediaId,
|
||||
@Nullable Bundle rootExtra);
|
||||
}
|
||||
|
||||
public MediaBrowser2(Context context, SessionToken token, BrowserCallback callback,
|
||||
Executor executor) {
|
||||
super(context, token, callback, executor);
|
||||
mProvider = (MediaBrowser2Provider) getProvider();
|
||||
}
|
||||
|
||||
@Override
|
||||
MediaBrowser2Provider createProvider(Context context, SessionToken token,
|
||||
ControllerCallback callback, Executor executor) {
|
||||
return ApiLoader.getProvider(context)
|
||||
.createMediaBrowser2(this, context, token, (BrowserCallback) callback, executor);
|
||||
}
|
||||
|
||||
public void getBrowserRoot(Bundle rootHints) {
|
||||
mProvider.getBrowserRoot_impl(rootHints);
|
||||
}
|
||||
}
|
||||
@@ -104,7 +104,13 @@ public class MediaController2 extends MediaPlayerBase {
|
||||
// session whose session binder is only valid while it's active.
|
||||
// prevent a controller from reusable after the
|
||||
// session is released and recreated.
|
||||
mProvider = ApiLoader.getProvider(context)
|
||||
mProvider = createProvider(context, token, callback, executor);
|
||||
}
|
||||
|
||||
MediaController2Provider createProvider(@NonNull Context context,
|
||||
@NonNull SessionToken token, @NonNull ControllerCallback callback,
|
||||
@NonNull Executor executor) {
|
||||
return ApiLoader.getProvider(context)
|
||||
.createMediaController2(this, context, token, callback, executor);
|
||||
}
|
||||
|
||||
|
||||
26
media/java/android/media/update/MediaBrowser2Provider.java
Normal file
26
media/java/android/media/update/MediaBrowser2Provider.java
Normal file
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright 2018 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package android.media.update;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
/**
|
||||
* @hide
|
||||
*/
|
||||
public interface MediaBrowser2Provider extends MediaController2Provider {
|
||||
void getBrowserRoot_impl(Bundle rootHints);
|
||||
}
|
||||
@@ -19,7 +19,10 @@ package android.media.update;
|
||||
import android.annotation.Nullable;
|
||||
import android.content.Context;
|
||||
import android.media.IMediaSession2Callback;
|
||||
import android.media.MediaBrowser2;
|
||||
import android.media.MediaBrowser2.BrowserCallback;
|
||||
import android.media.MediaController2;
|
||||
import android.media.MediaController2.ControllerCallback;
|
||||
import android.media.MediaPlayerBase;
|
||||
import android.media.MediaSession2;
|
||||
import android.media.MediaSessionService2;
|
||||
@@ -53,7 +56,10 @@ public interface StaticProvider {
|
||||
String packageName, IMediaSession2Callback callback);
|
||||
MediaController2Provider createMediaController2(
|
||||
MediaController2 instance, Context context, SessionToken token,
|
||||
MediaController2.ControllerCallback callback, Executor executor);
|
||||
ControllerCallback callback, Executor executor);
|
||||
MediaBrowser2Provider createMediaBrowser2(
|
||||
MediaBrowser2 instance, Context context, SessionToken token,
|
||||
BrowserCallback callback, Executor executor);
|
||||
MediaSessionService2Provider createMediaSessionService2(
|
||||
MediaSessionService2 instance);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user