Justin Klaassen | b8042fc | 2018-04-15 00:41:15 -0400 | [diff] [blame] | 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 | MediaPlayerBase 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 | static final class Builder extends MediaSession2ImplBase.BuilderBase< |
| 43 | MediaLibrarySession, MediaLibrarySession.MediaLibrarySessionCallback> { |
| 44 | Builder(Context context) { |
| 45 | super(context); |
| 46 | } |
| 47 | |
| 48 | @Override |
| 49 | public @NonNull MediaLibrarySession build() { |
| 50 | if (mCallbackExecutor == null) { |
| 51 | mCallbackExecutor = new MainHandlerExecutor(mContext); |
| 52 | } |
| 53 | if (mCallback == null) { |
| 54 | mCallback = new MediaLibrarySession.MediaLibrarySessionCallback() {}; |
| 55 | } |
| 56 | return new MediaLibrarySession(new MediaLibrarySessionImplBase(mContext, |
| 57 | new MediaSessionCompat(mContext, mId), mId, mPlayer, mPlaylistAgent, |
| 58 | mVolumeProvider, mSessionActivity, mCallbackExecutor, mCallback)); |
| 59 | } |
| 60 | } |
| 61 | } |