Example usage for android.media AudioManager GET_DEVICES_OUTPUTS

List of usage examples for android.media AudioManager GET_DEVICES_OUTPUTS

Introduction

In this page you can find the example usage for android.media AudioManager GET_DEVICES_OUTPUTS.

Prototype

int GET_DEVICES_OUTPUTS

To view the source code for android.media AudioManager GET_DEVICES_OUTPUTS.

Click Source Link

Document

Specifies to the AudioManager#getDevices(int) method to include sink (i.e.

Usage

From source file:com.google.sample.aaudio.play.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mPlaybackDeviceSpinner = findViewById(R.id.playbackDevicesSpinner);
    mPlaybackDeviceSpinner.setDirectionType(AudioManager.GET_DEVICES_OUTPUTS);
    mPlaybackDeviceSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override//w ww  .  ja  v  a2 s . c  om
        public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
            PlaybackEngine.setAudioDeviceId(getPlaybackDeviceId());
        }

        @Override
        public void onNothingSelected(AdapterView<?> adapterView) {

        }
    });

    mBufferSizeSpinner = findViewById(R.id.bufferSizeSpinner);
    mBufferSizeSpinner.setAdapter(new SimpleAdapter(this, createBufferSizeOptionsList(), // list of buffer size options
            R.layout.buffer_sizes_spinner, // the xml layout
            new String[] { getString(R.string.buffer_size_description_key) }, // field to display
            new int[] { R.id.bufferSizeOption })); // View to show field in

    mBufferSizeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
            PlaybackEngine.setBufferSizeInBursts(getBufferSizeInBursts());
        }

        @Override
        public void onNothingSelected(AdapterView<?> adapterView) {

        }
    });

    // initialize native audio system
    mEngineCreated = PlaybackEngine.create();

    // Periodically update the UI with the output stream latency
    mLatencyText = findViewById(R.id.latencyText);
    setupLatencyUpdater();
}

From source file:com.google.sample.aaudio.echo.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    statusText = findViewById(R.id.status_view_text);
    toggleEchoButton = findViewById(R.id.button_toggle_echo);
    toggleEchoButton.setOnClickListener(new View.OnClickListener() {
        @Override//  www . j ava  2  s  . co m
        public void onClick(View view) {
            toggleEcho();
        }
    });
    toggleEchoButton.setText(getString(R.string.start_echo));

    recordingDeviceSpinner = findViewById(R.id.recording_devices_spinner);
    recordingDeviceSpinner.setDirectionType(AudioManager.GET_DEVICES_INPUTS);
    recordingDeviceSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
            EchoEngine.setRecordingDeviceId(getRecordingDeviceId());
        }

        @Override
        public void onNothingSelected(AdapterView<?> adapterView) {
            // Do nothing
        }
    });

    playbackDeviceSpinner = findViewById(R.id.playback_devices_spinner);
    playbackDeviceSpinner.setDirectionType(AudioManager.GET_DEVICES_OUTPUTS);
    playbackDeviceSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
            EchoEngine.setPlaybackDeviceId(getPlaybackDeviceId());
        }

        @Override
        public void onNothingSelected(AdapterView<?> adapterView) {
            // Do nothing
        }
    });

    EchoEngine.create();
}

From source file:com.google.sample.oboe.hellooboe.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mAudioApiSpinner = findViewById(R.id.audioApiSpinner);
    mAudioApiSpinner//  w w  w  .  jav  a  2  s. c o  m
            .setAdapter(new SimpleAdapter(this, createAudioApisOptionsList(), R.layout.audio_apis_spinner, // the xml layout
                    new String[] { getString(R.string.audio_api_description_key) }, // field to display
                    new int[] { R.id.audioApiOption } // View to show field in
    ));

    mAudioApiSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
            PlaybackEngine.setAudioApi(i);
        }

        @Override
        public void onNothingSelected(AdapterView<?> adapterView) {

        }
    });

    mPlaybackDeviceSpinner = findViewById(R.id.playbackDevicesSpinner);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        mPlaybackDeviceSpinner.setDirectionType(AudioManager.GET_DEVICES_OUTPUTS);
        mPlaybackDeviceSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
                PlaybackEngine.setAudioDeviceId(getPlaybackDeviceId());
            }

            @Override
            public void onNothingSelected(AdapterView<?> adapterView) {

            }
        });
    }

    mBufferSizeSpinner = findViewById(R.id.bufferSizeSpinner);
    mBufferSizeSpinner.setAdapter(new SimpleAdapter(this, createBufferSizeOptionsList(), // list of buffer size options
            R.layout.buffer_sizes_spinner, // the xml layout
            new String[] { getString(R.string.buffer_size_description_key) }, // field to display
            new int[] { R.id.bufferSizeOption } // View to show field in
    ));

    mBufferSizeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
            PlaybackEngine.setBufferSizeInBursts(getBufferSizeInBursts());
        }

        @Override
        public void onNothingSelected(AdapterView<?> adapterView) {

        }
    });

    // initialize native audio system
    PlaybackEngine.create();

    // Periodically update the UI with the output stream latency
    mLatencyText = findViewById(R.id.latencyText);
    setupLatencyUpdater();
}

From source file:com.example.android.wearable.speaker.MainActivity.java

/**
 * Determines if the wear device has a built-in speaker and if it is supported. Speaker, even if
 * physically present, is only supported in Android M+ on a wear device..
 *///from   w w  w .j  a  va2  s  .co m
public final boolean speakerIsSupported() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        PackageManager packageManager = getPackageManager();
        // The results from AudioManager.getDevices can't be trusted unless the device
        // advertises FEATURE_AUDIO_OUTPUT.
        if (!packageManager.hasSystemFeature(PackageManager.FEATURE_AUDIO_OUTPUT)) {
            return false;
        }
        AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
        AudioDeviceInfo[] devices = audioManager.getDevices(AudioManager.GET_DEVICES_OUTPUTS);
        for (AudioDeviceInfo device : devices) {
            if (device.getType() == AudioDeviceInfo.TYPE_BUILTIN_SPEAKER) {
                return true;
            }
        }
    }
    return false;
}