Home | History | Annotate | Download | only in media
      1 /*
      2  * Copyright (C) 2017 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 android.media;
     18 
     19 import android.os.Handler;
     20 
     21 /**
     22  * Helper class {@link AudioTrack}, {@link AudioRecord}, {@link MediaPlayer} and {@link MediaRecorder}
     23  * to handle the forwarding of native events to the appropriate listener
     24  * (potentially) handled in a different thread.
     25  * @hide
     26  */
     27 class NativeRoutingEventHandlerDelegate {
     28     private AudioRouting mAudioRouting;
     29     private AudioRouting.OnRoutingChangedListener mOnRoutingChangedListener;
     30     private Handler mHandler;
     31 
     32     NativeRoutingEventHandlerDelegate(final AudioRouting audioRouting,
     33             final AudioRouting.OnRoutingChangedListener listener, Handler handler) {
     34         mAudioRouting = audioRouting;
     35         mOnRoutingChangedListener = listener;
     36         mHandler = handler;
     37     }
     38 
     39     void notifyClient() {
     40         if (mHandler != null) {
     41             mHandler.post(new Runnable() {
     42                 @Override
     43                 public void run() {
     44                     if (mOnRoutingChangedListener != null) {
     45                         mOnRoutingChangedListener.onRoutingChanged(mAudioRouting);
     46                     }
     47                 }
     48             });
     49         }
     50     }
     51 }
     52