How can I catch itunes events?

I 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 application programmed in C #, but it cannot be caught when the song changes. Did I lose something?

Is there any other way to catch the iTunes track change event?

+3
source share
3 answers

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
}

what he:)

+1
source

In fact, you are subscribing to the wrong event to capture this information.

Here is a snippet of code 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;

    }
+5
source

"", "". , . , ? ( , ).

+1
source

Source: https://habr.com/ru/post/1714462/


All Articles