当前位置 : 主页 > 编程语言 > c语言 >

c# – 我如何捕捉itunes事件?

来源:互联网 收集:自由互联 发布时间:2021-06-25
我添加了这段代码 iTunes.OnPlayerPlayingTrackChangedEvent += new _IiTunesEvents_OnPlayerPlayingTrackChangedEventEventHandler(iTunes_OnPlayerPlayingTrackChangedEvent); 和这段代码 private void iTunes_OnPlayerPlayingTrackChangedEve
我添加了这段代码

iTunes.OnPlayerPlayingTrackChangedEvent += new _IiTunesEvents_OnPlayerPlayingTrackChangedEventEventHandler(iTunes_OnPlayerPlayingTrackChangedEvent);

和这段代码

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();
                }
            }
        }
    }

我的应用程序是用c#编程的,但是当歌曲改变时它没有捕获.我错过了什么吗?

有没有其他方法来捕捉iTunes曲目更改事件?

您实际上订阅了错误的事件来捕获此信息.

这是一个代码片段,可以为您提供所需内容:

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;

    }
网友评论