다음 예에서는 앱이 getDevices() 메서드를 FEATURE_AUDIO_OUTPUT 값과 함께 사용하여 모든 오디오 출력을 열거합니다.
AudioManageraudioManager=(AudioManager)context.getSystemService(Context.AUDIO_SERVICE);funaudioOutputAvailable(type:Int):Boolean{if(!packageManager.hasSystemFeature(PackageManager.FEATURE_AUDIO_OUTPUT)){returnfalse}returnaudioManager.getDevices(AudioManager.GET_DEVICES_OUTPUTS).any{it.type==type}}// True if the device has a speakeraudioOutputAvailable(AudioDeviceInfo.TYPE_BUILTIN_SPEAKER)// True if a Bluetooth headset is paired and connectedaudioOutputAvailable(AudioDeviceInfo.TYPE_BLUETOOTH_A2DP)// True if a BLE broadcast group device is paired and connectedaudioOutputAvailable(AudioDeviceInfo.TYPE_BLE_BROADCAST)// True if a BLE headset is paired and connectedaudioOutputAvailable(AudioDeviceInfo.TYPE_BLE_HEADSET)// True if a BLE speaker is paired and connectedaudioOutputAvailable(AudioDeviceInfo.TYPE_BLE_SPEAKER)
최상의 사용자 환경을 제공하려면 앱에서 블루투스 헤드폰이나 스피커가 시계에 연결되어 있을 때만 미디어를 재생하도록 해야 합니다.
오디오 출력에 사용할 기본 기기 선택
앱의 사용 사례와 앱의 핵심 환경에 대한 오디오의 중요성에 따라 사용자가 앱의 오디오 출력에 어떻게 참여할 것인지 선택합니다.
사용자가 미디어 출력 기기를 선택하도록 허용
Wear OS 5부터 시스템은 사용자가 미디어를 재생하고 현재 재생 중인 미디어 콘텐츠에 관한 정보를 표시할 기기를 선택할 수 있는 UI를 제공합니다.
Wear OS 5 이상을 실행하는 기기에서 오디오 재생을 제공하려고 할 때 연결된 블루투스 헤드셋이 없음을 앱에서 감지하는 경우 사용자를 미디어 출력 전환기로 바로 안내하는 것이 좋습니다. 미디어 출력 전환기를 지원하지 않는 기기에서는 사용자를 시스템 설정의 블루투스 페이지로 안내하는 ACTION_BLUETOOTH_SETTINGS 인텐트 작업을 호출합니다.
기기에 있는 경우 항상 사용할 수 있는 내장 스피커와 달리 블루투스 헤드셋은 앱이 실행되는 동안 페어링되거나 페어링 해제될 수 있습니다. 앱을 계속 진행하려면 헤드셋이 필요한 경우 registerAudioDeviceCallback을 사용하여 사용자가 블루투스 헤드셋을 연결하고 연결 해제하는 시점을 감지하도록 콜백을 등록합니다.
audioManager.registerAudioDeviceCallback(object:AudioDeviceCallback(){overridefunonAudioDevicesAdded(addedDevices:Array<outAudioDeviceInfo>?){super.onAudioDevicesAdded(addedDevices)if(audioOutputAvailable(AudioDeviceInfo.TYPE_BLUETOOTH_A2DP)||audioOutputAvailable(AudioDeviceInfo.TYPE_BLE_BROADCAST)||audioOutputAvailable(AudioDeviceInfo.TYPE_BLE_HEADSET)||audioOutputAvailable(AudioDeviceInfo.TYPE_BLE_SPEAKER)){// A Bluetooth or BLE device is connected and available for playback.}}overridefunonAudioDevicesRemoved(removedDevices:Array<outAudioDeviceInfo>?){super.onAudioDevicesRemoved(removedDevices)if(!(audioOutputAvailable(AudioDeviceInfo.TYPE_BLUETOOTH_A2DP)) && !(audioOutputAvailable(AudioDeviceInfo.TYPE_BLE_BROADCAST)) && !(audioOutputAvailable(AudioDeviceInfo.TYPE_BLE_HEADSET)) && !(audioOutputAvailable(AudioDeviceInfo.TYPE_BLE_SPEAKER))){// No Bluetooth or BLE devices are connected anymore.}}},null)
오디오 출력을 제공하려고 할 때 연결된 블루투스 헤드셋이 없음을 앱에서 감지하는 경우 오류 메시지를 표시하지 마세요. 대신 더 쉽게 연결할 수 있도록 사용자에게 블루투스 설정으로 직접 이동하라고 제안합니다. ACTION_BLUETOOTH_SETTINGS를 사용하여 인텐트를 전송하면 됩니다.
대부분의 Wear OS 기기에는 내장 스피커가 있습니다. 앱이 사운드를 포함하는 미디어 외 사용 사례를 제공하는 경우 스피커를 사용하여 사용자의 참여를 한층 더 높일 수 있습니다. 예를 들어 스피커가 장착된 Wear OS 기기는 오디오 알림이 포함된 시계나 타이머 알람을 트리거하고 피트니스 앱은 스피커를 사용하여 운동 안내를 제공할 수 있습니다.
참고: 내장 스피커는 미디어 콘텐츠 청취에 가장 적합한 환경을 제공하지는 않습니다. 이러한 용도로 설계되지 않았기 때문입니다.
적절한 오디오 출력이 감지되고 선택되면 Wear OS에서 오디오를 재생하는 프로세스는 모바일 또는 기타 기기에서와 동일합니다. 자세한 내용은 MediaPlayer 개요를 참고하세요.
미디어 스트리밍 및 다운로드와 같은 고급 기능에 더 쉽게 액세스하려면 ExoPlayer를 사용하세요.
오디오 포커스 관리와 같은 오디오 앱 권장사항을 따라야 합니다.
내장 스피커를 통한 의도하지 않은 미디어 재생 방지
미디어 앱은 다음 안내에 따라 앱이 의도치 않게 내장 시계 스피커에서 미디어 콘텐츠를 재생하지 않도록 할 수 있습니다. 안내는 앱에서 사용 중인 플레이어에 따라 다릅니다.
사용자가 미디어 재생을 시작하려고 하지만 외부 오디오 기기를 연결하지 않은 경우 이러한 기기를 시계에 연결하라는 메시지를 사용자에게 표시합니다.
이 페이지에 나와 있는 콘텐츠와 코드 샘플에는 콘텐츠 라이선스에서 설명하는 라이선스가 적용됩니다. 자바 및 OpenJDK는 Oracle 및 Oracle 계열사의 상표 또는 등록 상표입니다.
최종 업데이트: 2025-07-27(UTC)
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["필요한 정보가 없음","missingTheInformationINeed","thumb-down"],["너무 복잡함/단계 수가 너무 많음","tooComplicatedTooManySteps","thumb-down"],["오래됨","outOfDate","thumb-down"],["번역 문제","translationIssue","thumb-down"],["샘플/코드 문제","samplesCodeIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-07-27(UTC)"],[],[],null,["# Play audio on wearables\n\nThis guide describes how apps on Wear OS can use familiar Android APIs to play audio.\n\nDetect audio devices\n--------------------\n\n\nA Wear OS app must first detect whether the wearable device has an appropriate audio output.\nDevelopers can expect wearables to have at least one of the following audio outputs available:\n\n- [AudioDeviceInfo.TYPE_BUILTIN_SPEAKER](/reference/android/media/AudioDeviceInfo#TYPE_BUILTIN_SPEAKER): on devices that have a built-in speaker\n- [AudioDeviceInfo.TYPE_BLUETOOTH_A2DP](/reference/android/media/AudioDeviceInfo#TYPE_BLUETOOTH_A2DP): when a Bluetooth headset is paired and connected\n- [AudioDeviceInfo.TYPE_BLE_BROADCAST](/reference/android/media/AudioDeviceInfo#TYPE_BLE_BROADCAST): when a Bluetooth Low Energy (BLE) broadcast group device is paired and connected\n- [AudioDeviceInfo.TYPE_BLE_HEADSET](/reference/android/media/AudioDeviceInfo#TYPE_BLE_HEADSET): when a BLE headset is paired and connected\n- [AudioDeviceInfo.TYPE_BLE_SPEAKER](/reference/android/media/AudioDeviceInfo#TYPE_BLE_SPEAKER): when a BLE speaker is paired and connected\n\n\nIn the following example, the app uses the\n[getDevices()](/reference/android/media/AudioManager#getDevices(int))\nmethod in conjunction with the value of `FEATURE_AUDIO_OUTPUT` to enumerate all audio\noutputs. \n\n```kotlin\nAudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);\n\nfun audioOutputAvailable(type: Int): Boolean {\n if (!packageManager.hasSystemFeature(PackageManager.FEATURE_AUDIO_OUTPUT)) {\n return false\n }\n return audioManager.getDevices(AudioManager.GET_DEVICES_OUTPUTS).any { it.type == type }\n}\n\n// True if the device has a speaker\naudioOutputAvailable(AudioDeviceInfo.TYPE_BUILTIN_SPEAKER)\n\n// True if a Bluetooth headset is paired and connected\naudioOutputAvailable(AudioDeviceInfo.TYPE_BLUETOOTH_A2DP)\n\n// True if a BLE broadcast group device is paired and connected\naudioOutputAvailable(AudioDeviceInfo.TYPE_BLE_BROADCAST)\n\n// True if a BLE headset is paired and connected\naudioOutputAvailable(AudioDeviceInfo.TYPE_BLE_HEADSET)\n\n// True if a BLE speaker is paired and connected\naudioOutputAvailable(AudioDeviceInfo.TYPE_BLE_SPEAKER)\n```\n\nTo give the best user experience, your app should make sure to only play media when Bluetooth\nheadphones or speakers are connected to the watch.\n\nChoose preferred device for audio output\n----------------------------------------\n\nDepending on your app's use case, and the importance of audio to your app's core experience,\nchoose how you'd like users to engage with your app's audio output.\n\n### Let user choose media output device\n\nStarting in Wear OS 5, the system provides a UI that lets users choose which\ndevice should play media and show information about the currently-playing media\ncontent.\n\nIf your app detects that there isn't a Bluetooth headset connected when you want\nto provide audio playback on devices running Wear OS 5 or higher, offer to take\nthe user directly to media output switcher. On devices that don't support the\nmedia output switcher, invoke the [`ACTION_BLUETOOTH_SETTINGS`](/reference/android/provider/Settings#ACTION_BLUETOOTH_SETTINGS) intent\naction, which takes the user to the Bluetooth page in system settings.\n\nThe [`launchOutputSelection()`](https://github.com/google/horologist/blob/v0.5.26/media/audio/src/main/java/com/google/android/horologist/audio/SystemAudioRepository.kt#L108) method, part of the [Horologist](https://github.com/google/horologist) library\non GitHub, demonstrates how to let the user choose their media output device.\n\n### Bluetooth headset\n\n\nUnlike built-in speakers, which are always available if present on the device, a Bluetooth headset\ncan be paired or unpaired while an app runs. If the app requires a headset to continue,\nregister a callback to detect when\nthe user connects and disconnects a Bluetooth headset using\n[registerAudioDeviceCallback](/reference/android/media/AudioManager#registerAudioDeviceCallback(android.media.AudioDeviceCallback,%20android.os.Handler)):\n\n\u003cbr /\u003e\n\n```kotlin\naudioManager.registerAudioDeviceCallback(object : AudioDeviceCallback() {\n override fun onAudioDevicesAdded(addedDevices: Array\u003cout AudioDeviceInfo\u003e?) {\n super.onAudioDevicesAdded(addedDevices)\n if (audioOutputAvailable(AudioDeviceInfo.TYPE_BLUETOOTH_A2DP)\n || audioOutputAvailable(AudioDeviceInfo.TYPE_BLE_BROADCAST)\n || audioOutputAvailable(AudioDeviceInfo.TYPE_BLE_HEADSET)\n || audioOutputAvailable(AudioDeviceInfo.TYPE_BLE_SPEAKER)) {\n // A Bluetooth or BLE device is connected and available for playback.\n }\n }\n override fun onAudioDevicesRemoved(removedDevices: Array\u003cout AudioDeviceInfo\u003e?) {\n super.onAudioDevicesRemoved(removedDevices)\n if (!(audioOutputAvailable(AudioDeviceInfo.TYPE_BLUETOOTH_A2DP))\n && !(audioOutputAvailable(AudioDeviceInfo.TYPE_BLE_BROADCAST))\n && !(audioOutputAvailable(AudioDeviceInfo.TYPE_BLE_HEADSET))\n && !(audioOutputAvailable(AudioDeviceInfo.TYPE_BLE_SPEAKER))) {\n // No Bluetooth or BLE devices are connected anymore.\n }\n }\n}, null)\n \n```\n\n\u003cbr /\u003e\n\nIf your app detects that there isn't a Bluetooth headset connected when you want to provide audio\noutput, don't show an error message. Instead, offer to take the user directly to Bluetooth settings\nto make it easier for them to connect. This can be done by sending an intent with\n[ACTION_BLUETOOTH_SETTINGS](/reference/android/provider/Settings#ACTION_BLUETOOTH_SETTINGS):\n\n\u003cbr /\u003e\n\n```kotlin\n val intent = with (Intent(Settings.ACTION_BLUETOOTH_SETTINGS)) {\n addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK)\n putExtra(\"EXTRA_CONNECTION_ONLY\", true)\n putExtra(\"EXTRA_CLOSE_ON_CONNECT\", true)\n putExtra(\"android.bluetooth.devicepicker.extra.FILTER_TYPE\", 1)\n }\n startActivity(intent)\n \n```\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n### Built-in speakers\n\n\nMost Wear OS devices have built-in speakers. If your app offers a non-media use case that incorporates\nsound, consider using speakers to offer an extra dimension of engagement with the user. For\nexample, a speaker-equipped Wear OS device might trigger a clock or timer alarm, complete with\naudio notification, and fitness apps might use the speaker to provide exercise instructions.\n\n**Note:**Built-in speakers don't deliver the best experience for listening to media\ncontent as they aren't designed for this purpose.\n\n\nRefer to the [WearSpeakerSample](https://github.com/android/wear-os-samples/tree/main/WearSpeakerSample) for details.\n\n\u003cbr /\u003e\n\nPlay audio\n----------\n\n\nOnce you detect and choose a suitable audio output, the process for playing audio on Wear OS is the same\nas on mobile or other devices. For more information, see [MediaPlayer overview](/guide/topics/media/mediaplayer).\nFor easier access to more advanced features, such as streaming and downloading media, use\n[ExoPlayer](/guide/topics/media/exoplayer).\nMake sure to follow best practices for Audio apps such as [Managing Audio focus.](/guide/topics/media/media-apps/audio-focus)\n\n### Prevent unintended media playback through built-in speakers\n\n| **Note:** If you are targeting Android 15 (API level 35) or higher, the media output switcher provides the watch built-in speakers as one of the selectable options on supported Wear OS devices. To support this feature when using Exoplayer, update to version 1.5.0 or later version.\n\n\u003cbr /\u003e\n\n\nMedia apps can follow the following guidance to make sure the app does not unintentionally play\nmedia content on built-in watch speakers. The guidance is different based on which player the\napp is using.\n\n#### ExoPlayer\n\n\nIf your app is using ExoPlayer:\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n1. Call [setSuppressPlaybackOnUnsuitableOutput(true)](/reference/kotlin/androidx/media3/exoplayer/ExoPlayer.Builder#setSuppressPlaybackOnUnsuitableOutput(boolean))\n while building the ExoPlayer instance:\n\n ```kotlin\n ExoPlayer exoplayer = ExoPlayer.Builder(context)\n .setAudioAttributes(...)\n .setSuppressPlaybackWhenUnsuitableOutput(true)\n // ...\n .build()\n \n ```\n2. React to the playback suppression event by registering\n [WearUnsuitableOutputPlaybackSuppressionResolverListener](/reference/kotlin/androidx/media3/ui/WearUnsuitableOutputPlaybackSuppressionResolverListener)\n as a listener of the ExoPlayer instance:\n\n```kotlin\n exoPlayer.addListener(WearUnsuitableOutputPlaybackSuppressionResolverListener(context))\n \n```\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n#### Horologist Media toolkit\n\n\nThe [Horologist MediaToolkit](https://google.github.io/horologist/media-toolkit/) already contains logic to prevent unintended media playback on built-in watch speakers.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n#### Other media players\n\n- Make sure that media audio playback doesn't start unless a suitable output device, such as a headset or a set of external speakers, is [connected](/reference/android/media/AudioManager#getDevices(int)) to the watch. See the following list for suitable output devices for media apps:\n - [`TYPE_BLUETOOTH_A2DP`](/reference/android/media/AudioDeviceInfo#TYPE_BLUETOOTH_A2DP)\n - [`TYPE_BLE_BROADCAST`](/reference/android/media/AudioDeviceInfo#TYPE_BLE_BROADCAST)\n - [`TYPE_BLE_HEADSET`](/reference/android/media/AudioDeviceInfo#TYPE_BLE_HEADSET)\n - [`TYPE_BLE_SPEAKER`](/reference/android/media/AudioDeviceInfo#TYPE_BLE_SPEAKER)\n- Pause the playback if [AudioManager](/reference/android/media/AudioManager) notifies your app that an external audio output device [becomes disconnected from the watch](/reference/android/media/AudioDeviceCallback#onAudioDevicesRemoved(android.media.AudioDeviceInfo[])).\n- When the user attempts to initiate media playback but hasn't connected an external audio device, [prompt the user to connect](/training/wearables/apps/audio#prompt-the-user-to-connect-a-headset) such a device to their watch.\n\n\u003cbr /\u003e"]]