|
| 1 | +# Audio |
| 2 | + |
| 3 | +| Support | | |
| 4 | +| ------- |-| |
| 5 | +| Events | Yes | |
| 6 | + |
| 7 | +To play audio clips on your site you can use [`New-PodeWebAudio`](../../../Functions/Elements/New-PodeWebAudio). The audio can be set to auto-play and loop, and can also accept multiple sources and tracks. |
| 8 | + |
| 9 | +The sources specified can be done so via `-Source` and [`New-PodeWebAudioSource`](../../../Functions/Elements/New-PodeWebAudioSource). Sources can only be of type `MP3`, `OGG` and `WAV`, and at least one source must be specified: |
| 10 | + |
| 11 | +```powershell |
| 12 | +New-PodeWebCard -Content @( |
| 13 | + New-PodeWebAudio -Name 'example' -Source @( |
| 14 | + New-PodeWebAudioSource -Url 'https://samplelib.com/lib/preview/mp3/sample-6s.mp3' |
| 15 | + ) |
| 16 | +) |
| 17 | +``` |
| 18 | + |
| 19 | +Which looks like below: |
| 20 | + |
| 21 | + |
| 22 | + |
| 23 | +Any optional tracks you wish to specify can be done via `-Track` and [`New-PodeWebMediaTrack`](../../../Functions/Elements/New-PodeWebMediaTrack). Tracks can only be of type `VTT`, and can be used for subtitles, captions, metadata, etc. |
| 24 | + |
| 25 | +The `-Language` is mandatory if the track's `-Type` is subtitles, and should be a [2-letter language code](https://www.w3schools.com/tags/ref_language_codes.asp). |
| 26 | + |
| 27 | +```powershell |
| 28 | +New-PodeWebCard -Content @( |
| 29 | + New-PodeWebAudio -Name 'example' -Source @( |
| 30 | + New-PodeWebAudioSource -Url 'https://samplelib.com/lib/preview/mp3/sample-6s.mp3' |
| 31 | + ) ` |
| 32 | + -Tracks @( |
| 33 | + New-PodeWebMediaSource -Url '/some/url/path/english.vtt' -Language 'en' -Title 'English' -Type 'subtitles' -Default |
| 34 | + ) |
| 35 | +) |
| 36 | +``` |
| 37 | + |
| 38 | +## Size |
| 39 | + |
| 40 | +The `-Width` of an audio element has the default unit of `%`. If `0` is specified then `20%` is used instead. Any custom value such as `100px` can be used, but if a plain number is used then `%` is appended. |
| 41 | + |
| 42 | +## Events |
| 43 | + |
| 44 | +The following specific events are supported by the Audio element, and can be registered via [`Register-PodeWebMediaEvent`](../../../Functions/Events/Register-PodeWebMediaEvent): |
| 45 | + |
| 46 | +| Name | Description | |
| 47 | +| ---- | ----------- | |
| 48 | +| CanPlay | Fires when the browser is ready to play the audio | |
| 49 | +| Ended | Fires when the audio has finished playing, unless looping | |
| 50 | +| Pause | Fires when the audio is paused | |
| 51 | +| Play | Fires when the audio is played, or un-paused | |
| 52 | + |
| 53 | +Example: |
| 54 | + |
| 55 | +```powershell |
| 56 | +New-PodeWebAudio -Name 'example' -Source @( |
| 57 | + New-PodeWebAudioSource -Id 'sample' -Url 'https://samplelib.com/lib/preview/mp3/sample-6s.mp3' |
| 58 | +) | |
| 59 | +Register-PodeWebMediaEvent -Type Play -ScriptBlock { |
| 60 | + Show-PodeWebToast -Title 'Action' -Message $EventType |
| 61 | +} |
| 62 | +``` |
0 commit comments