how do i catch itunes events?
-
11-09-2019 - |
Question
i have added this code
iTunes.OnPlayerPlayingTrackChangedEvent += new _IiTunesEvents_OnPlayerPlayingTrackChangedEventEventHandler(iTunes_OnPlayerPlayingTrackChangedEvent);
and this code
private void iTunes_OnPlayerPlayingTrackChangedEvent(object iTrack)
{
if (iTunes.CurrentTrack != null)
{
if (iTunes.CurrentTrack.Artist != null & iTunes.CurrentTrack.Album != null & iTunes.CurrentTrack.Name != null)
{
artist = iTunes.CurrentTrack.Artist;
album = iTunes.CurrentTrack.Album;
title = iTunes.CurrentTrack.Name;
if (!NowPlaying.IsBusy)
{
NowPlaying.RunWorkerAsync();
}
}
}
}
to my app thats programmed in c# but its not catching when the song changes. Am i Missing Something?
is there any other way to catch iTunes track changed event?
Solution 3
I figured out a way to make it work.
First of all I added a timer
Then every 1 second it checks
try
{
if (iTunes.CurrentTrack.Artist != artist | iTunes.CurrentTrack.Album != album | iTunes.CurrentTrack.Name != title)
{
//Code to update UI here
}
}
catch
{
//Nothing Here! this is just so your the app doesn't blow up if iTunes is busy. instead it will just try again in 1 second
}
that's it :)
OTHER TIPS
You're actually subscribing to the wrong event to capture this info.
Here is a code snippet that will give you what you want:
iTunesApp app = new iTunesApp();
public Form1()
{
InitializeComponent();
app.OnPlayerPlayEvent += new _IiTunesEvents_OnPlayerPlayEventEventHandler(app_OnPlayerPlayEvent);
}
public void app_OnPlayerPlayEvent(object iTrack)
{
IITTrack currentTrack = (IITTrack)iTrack;
string trackName = currentTrack.Name;
string artist = currentTrack.Artist;
string album = currentTrack.Album;
}
You should use "or", not "and". In your code, it will only report if the artist and the album and the songname change. Is that what you want? (because if I play another song in the same album, the UI won't update).
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow