I have a Windows PowerShell script (running under Windows 11) which polls the iTunes application on the local computer to find out the currently playing track. This could be handled more elegantly by responding to the OnPlayerPlayEvent and OnPlayerStopEvent events. However, I have run out of ideas how to hook an event handler to these events.
What I have tried so far:
$eventHandler = {
# Do something when the OnPlayerPlayEvent is raised
Write-Host "iTunes is now playing $($iTunes.CurrentTrack.Name)"
}
$global:iTunes = New-Object -ComObject iTunes.Application
$iTunes.OnPlayerPlayEvent = Register-ObjectEvent -InputObject $global:iTunes -EventName "OnPlayerPlayEvent" -Action $eventHandler -SourceIdentifier "iTunesPlayerPlay"
This outputs the following error message:
Register-ObjectEvent : Cannot register for the specified event. An event with the name 'OnPlayerPlayEvent' does not exist.
Parameter name: eventName
I tried to vary "OnPlayerPlayEvent", like prefixing it with the name of the interface "_IiTunesEvents", or changing to all lowercase, but with no luck.
Resources I have (tried to) use:
- /?q=itunes%20com - the iTunes COM SDK, to which many places on the internet refer, but it has no helpful examples
After all, I am not even sure whether the problem is with iTunes, with PowerShell, or with how I try to register the event handler.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744290650a4567013.html
评论列表(0条)