Public/New-BTAudio.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
function New-BTAudio
{
    <#
        .SYNOPSIS
        Creates a new Audio Element for Toast Notifications.
 
        .DESCRIPTION
        The New-BTAudioElement cmdlet creates a new Audio Element for Toast Notifications.
     
        You can use the parameters of New-BTAudioElement to select an audio file or a standard notification sound (including alarms). Alternativly you can specify that a Toast Notification should be silent.
 
        .INPUTS
        None
 
        You cannot pipe input to this cmdlet.
 
        .OUTPUTS
        Audio
         
        .EXAMPLE
        New-BTAudioElement -Source SMS
 
        Creates an Audio Element which will cause a Toast Notification to play the standard Microsoft 'SMS' sound.
 
        .EXAMPLE
        New-BTAudioElement -Path 'C:\Music\FavSong.mp3'
 
        Creates an Audio Element which will cause a Toast Notification to play the specified song.
 
        .EXAMPLE
        New-BTAudioElement -Silent
 
        Creates an Audio Element which will cause a Toast Notification to be silent.
 
        .PARAMETER Path
        The full path to an audio file. Supported file types include:
 
        *.aac
        *.flac
        *.m4a
        *.mp3
        *.wav
        *.wma
 
        .LINK
        https://github.com/Windos/BurntToast
    #>


    [CmdletBinding()]
    [OutputType([Microsoft.Toolkit.Uwp.Notifications.ToastAudio])]
    param
    (
        [Parameter()]
        [uri] $Source,

        [Parameter()]
        [switch] $Loop,

        [Parameter()]
        [switch] $Silent
    )

    #TODO: Add ability to select 'ms-winsoundevent:Notification' sounds

    $Audio = [Microsoft.Toolkit.Uwp.Notifications.ToastAudio]::new()
    
    if ($Source)
    {
        $Audio.Src = $Source
    }

    $Audio.Loop = $Loop
    $Audio.Silent = $Silent

    $Audio
}