Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 25 additions & 23 deletions runtimes/playing-audio.mdx
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
---
title: 'Playing Audio'
description: 'To learn more on how to add audio to your Rive file, see [Audio Events](/editor/events/audio-events).'
title: "Playing Audio"
description: "Playing Rive audio events"
---

To learn more on how to add audio to your Rive file, see [Audio Events](/editor/events/audio-events).

<Warning>
On web, some browsers restrict audio from playing until the web page is interacted with. This applies to any audio, not just Rive audio.<br/>
The web page needs to receive some interaction (touch/click) before sound is played. This interaction can be anything on the browser and doesn't need to be a Rive specific interaction.
On web, some browsers restrict audio from playing until the web page is interacted with. This applies to any audio, not just Rive audio.\
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was removing the line break and replacing it with \ on purpose?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Mintlify editor is weird, even when I revert everything and just make the singular edit, it formats the document all weird. Someone told me it's normal, but I can go and try again if there's a different way. I did it via the Mintlify markdown editor.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it's still treating it like a line break so 👍

The web page needs to receive some interaction (touch/click) before sound is played. This interaction can be anything on the browser and doesn't need to be a Rive specific interaction.
</Warning>

## Embedded Assets

Embedded assets require no additional work to play audio. However, on some platforms, additional work may be required to set up audio to mix, duck, or otherwise change more global settings for playing audio. See **Audio Settings** below.
Expand All @@ -16,48 +19,49 @@ Embedded assets require no additional work to play audio. However, on some platf
Referenced assets require a little bit more work to play audio. Audio will still automatically play, but the audio file(s) must be loaded when a Rive runtime attempts to play audio. For more information, see [Loading Assets](/runtimes/loading-assets).

<Tabs>
<Tab title="Apple">

<Tab title="Apple">
```swift IOS
// Load a referenced audio file, with the same name and extension as added in the editor
let viewModel = RiveViewModel(fileName: "my_rive_file") { asset, data, factory -> Bool in
guard let audioAsset = asset as? RiveAudioAsset else {
return false
}

guard let url = Bundle.main.url(
forResource: audioAsset.uniqueName(),
withExtension: audioAsset.fileExtension()
) else {
print("Failed to load asset \(asset.uniqueFilename()) from bundle.")
return false
}

guard let data = try? Data(contentsOf: url) else {
print("Failed to load \(url) from bundle.")
return false
}

audioAsset.audio(factory.decodeAudio(data))
return true
}
```
</Tab>
</Tab>
</Tabs>

## Audio Settings
## Audio Settings

<Tabs>
<Tab title="Apple">
On iOS, playing audio will respect your `AVAudioSession` shared instance settings. For more information, see [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avaudiosession) on `AVAudioSession`. Using this, you can choose to mix audio, duck audio, and more. You can update your shared instance early in your app lifecycle if you would like to ensure all Rive audio plays with the correct settings.
```swift IOS
// Example: Ignore the silent switch, and mix with other audio
let category: AVAudioSession.Category = .playback
let options: AVAudioSession.CategoryOptions = [.mixWithOthers]
AVAudioSession.sharedInstance().setCategory(category, options: options)
```
</Tab>
<Tab title="Apple">
On iOS, playing audio will respect your `AVAudioSession` shared instance settings. For more information, see [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avaudiosession) on `AVAudioSession`. Using this, you can choose to mix audio, duck audio, and more. You can update your shared instance early in your app lifecycle if you would like to ensure all Rive audio plays with the correct settings.

```swift IOS
// Example: Ignore the silent switch, and mix with other audio
let category: AVAudioSession.Category = .playback
let options: AVAudioSession.CategoryOptions = [.mixWithOthers]
AVAudioSession.sharedInstance().setCategory(category, options: options)
```
</Tab>
</Tabs>

## Setting Volume

An artboard is capable of setting its volume. A parent artboard will set the volume of all component instances; however, setting a component's volume will **not** update the parent's volume.
Expand All @@ -66,6 +70,4 @@ An artboard is capable of setting its volume. A parent artboard will set the vol
// Set the current artboard's volume to 50%
let viewModel = RiveViewModel(fileName: "my_rive_file")
viewModel.riveModel?.volume = 0.5
```


```