1 /* 2 * Copyright 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package androidx.media; 18 19 import android.annotation.TargetApi; 20 import android.app.PendingIntent; 21 import android.content.Context; 22 import android.os.Build; 23 import android.support.v4.media.session.MediaSessionCompat; 24 25 import androidx.annotation.NonNull; 26 import androidx.media.MediaLibraryService2.MediaLibrarySession; 27 28 import java.util.concurrent.Executor; 29 30 @TargetApi(Build.VERSION_CODES.KITKAT) 31 class MediaLibrarySessionImplBase extends MediaSession2ImplBase { 32 MediaLibrarySessionImplBase(Context context, 33 MediaSessionCompat sessionCompat, String id, 34 MediaPlayerInterface player, MediaPlaylistAgent playlistAgent, 35 VolumeProviderCompat volumeProvider, PendingIntent sessionActivity, 36 Executor callbackExecutor, 37 MediaSession2.SessionCallback callback) { 38 super(context, sessionCompat, id, player, playlistAgent, volumeProvider, sessionActivity, 39 callbackExecutor, callback); 40 } 41 42 @Override 43 MediaSession2 createInstance() { 44 return new MediaLibrarySession(this); 45 } 46 47 static final class Builder extends MediaSession2ImplBase.BuilderBase< 48 MediaLibrarySession, MediaLibrarySession.MediaLibrarySessionCallback> { 49 Builder(Context context) { 50 super(context); 51 } 52 53 @Override 54 public @NonNull MediaLibrarySession build() { 55 if (mCallbackExecutor == null) { 56 mCallbackExecutor = new MainHandlerExecutor(mContext); 57 } 58 if (mCallback == null) { 59 mCallback = new MediaLibrarySession.MediaLibrarySessionCallback() {}; 60 } 61 return new MediaLibrarySession(new MediaLibrarySessionImplBase(mContext, 62 new MediaSessionCompat(mContext, mId), mId, mPlayer, mPlaylistAgent, 63 mVolumeProvider, mSessionActivity, mCallbackExecutor, mCallback)); 64 } 65 } 66 } 67