Hi,
I'm currently trying to register an ObjectEvent and am having no luck at all !
I'm trying to play a Mp3 file with 'system.windows.media.mediaplayer' and when the Mp3 file ends, a "Test" is echoed back to the console (just for testing, once I can get that working, I can do the rest of the action by myself).
the code i'm using is;
Add-Type -AssemblyName presentationCore$mediaPlayer = New-Object system.windows.media.mediaplayer
Register-ObjectEvent -InputObject $mediaPlayer -EventName MediaOpened -Action {Write-Host "hi"}
$mediaPlayer.open([uri]"$("C:\test.mp3")")
$mediaPlayer.Play()
The mp3 plays fine (I can hear it), but for some reason the handler doesn't respond with the echo on the console when the mp3 finishes.
Is there any reason as to why?
The reason for this is there's a .txt file with Mp3 locations, I need a script that loops through each file playing each song, however I also need the script to listen on the network for a packet (based on the contents of the packet, the script might pause the song, to move onto the next song). So I hoping that I could either use a handler to tell when the mp3 has finished, or a background job, then move onto the next song, whilst keeping the script listening on the network socket.
hope this makes sense !
Josh