Search in sources :

Example 1 with AudioDeviceCallback

use of android.media.AudioDeviceCallback in project vlc-android by videolan.

the class MediaPlayer method createAudioDeviceCallback.

@TargetApi(Build.VERSION_CODES.M)
private AudioDeviceCallback createAudioDeviceCallback() {
    return new AudioDeviceCallback() {

        private SparseArray<Long> mEncodedDevices = new SparseArray<>();

        private void onAudioDevicesChanged() {
            long encodingFlags = 0;
            for (int i = 0; i < mEncodedDevices.size(); ++i) encodingFlags |= mEncodedDevices.valueAt(i);
            updateAudioOutputDevice(encodingFlags, "pcm");
        }

        @RequiresApi(Build.VERSION_CODES.M)
        @Override
        public void onAudioDevicesAdded(AudioDeviceInfo[] addedDevices) {
            for (AudioDeviceInfo info : addedDevices) {
                if (!info.isSink())
                    continue;
                long encodingFlags = getEncodingFlags(info.getEncodings());
                if (encodingFlags != 0)
                    mEncodedDevices.put(info.getId(), encodingFlags);
            }
            onAudioDevicesChanged();
        }

        @RequiresApi(Build.VERSION_CODES.M)
        @Override
        public void onAudioDevicesRemoved(AudioDeviceInfo[] removedDevices) {
            for (AudioDeviceInfo info : removedDevices) {
                if (!info.isSink())
                    continue;
                mEncodedDevices.remove(info.getId());
            }
            onAudioDevicesChanged();
        }
    };
}
Also used : SparseArray(android.util.SparseArray) AudioDeviceCallback(android.media.AudioDeviceCallback) AudioDeviceInfo(android.media.AudioDeviceInfo) TargetApi(android.annotation.TargetApi)

Example 2 with AudioDeviceCallback

use of android.media.AudioDeviceCallback in project vlc-android by GeoffreyMetais.

the class MediaPlayer method createAudioDeviceCallback.

@TargetApi(Build.VERSION_CODES.M)
private AudioDeviceCallback createAudioDeviceCallback() {
    return new AudioDeviceCallback() {

        private SparseArray<Long> mEncodedDevices = new SparseArray<>();

        private void onAudioDevicesChanged() {
            long encodingFlags = 0;
            for (int i = 0; i < mEncodedDevices.size(); ++i) encodingFlags |= mEncodedDevices.valueAt(i);
            updateAudioOutputDevice(encodingFlags, "pcm");
        }

        @RequiresApi(Build.VERSION_CODES.M)
        @Override
        public void onAudioDevicesAdded(AudioDeviceInfo[] addedDevices) {
            for (AudioDeviceInfo info : addedDevices) {
                if (!info.isSink())
                    continue;
                long encodingFlags = getEncodingFlags(info.getEncodings());
                if (encodingFlags != 0)
                    mEncodedDevices.put(info.getId(), encodingFlags);
            }
            onAudioDevicesChanged();
        }

        @RequiresApi(Build.VERSION_CODES.M)
        @Override
        public void onAudioDevicesRemoved(AudioDeviceInfo[] removedDevices) {
            for (AudioDeviceInfo info : removedDevices) {
                if (!info.isSink())
                    continue;
                mEncodedDevices.remove(info.getId());
            }
            onAudioDevicesChanged();
        }
    };
}
Also used : SparseArray(android.util.SparseArray) AudioDeviceCallback(android.media.AudioDeviceCallback) AudioDeviceInfo(android.media.AudioDeviceInfo) TargetApi(android.annotation.TargetApi)

Aggregations

TargetApi (android.annotation.TargetApi)2 AudioDeviceCallback (android.media.AudioDeviceCallback)2 AudioDeviceInfo (android.media.AudioDeviceInfo)2 SparseArray (android.util.SparseArray)2