• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 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 com.android.car.carlauncher.homescreen.audio.media;
18 
19 import com.android.car.carlauncher.homescreen.audio.MediaLaunchHandler;
20 import com.android.car.media.common.source.MediaSource;
21 
22 /**
23  * Routes media launches to {@link MediaLaunchHandler}.
24  */
25 public class MediaLaunchRouter {
26     private static MediaLaunchRouter sInstance;
27     private MediaLaunchHandler mMediaLaunchHandler;
28 
29     /**
30      * @return an instance of {@link MediaLaunchRouter}.
31      */
getInstance()32     public static MediaLaunchRouter getInstance() {
33         if (sInstance == null) {
34             sInstance = new MediaLaunchRouter();
35         }
36         return sInstance;
37     }
38 
39     /**
40      * Register a {@link MediaLaunchHandler}.
41      */
registerMediaLaunchHandler(MediaLaunchHandler mediaLaunchHandler)42     public void registerMediaLaunchHandler(MediaLaunchHandler mediaLaunchHandler) {
43         mMediaLaunchHandler = mediaLaunchHandler;
44     }
45 
46     /**
47      * Dispatch a media source to {@link MediaLaunchHandler}
48      */
handleLaunchMedia(MediaSource mediaSource)49     public void handleLaunchMedia(MediaSource mediaSource) {
50         if (mediaSource != null) {
51             mMediaLaunchHandler.handleLaunchMedia(mediaSource);
52         }
53     }
54 }
55