我如何捕捉 itunes 活动?

发布于 2024-07-30 02:11:50 字数 911 浏览 5 评论 0原文

添加

        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 曲目更改事件吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

时间海 2024-08-06 02:11:50

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

这是一个代码片段,可以为您提供您想要的内容:

        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'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;

    }
Oo萌小芽oO 2024-08-06 02:11:50

你应该使用“或”,而不是“和”。 在您的代码中,它只会报告艺术家、专辑和歌曲名是否发生更改。 那是你要的吗? (因为如果我播放同一专辑中的另一首歌曲,用户界面将不会更新)。

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).

热鲨 2024-08-06 02:11:50

我想出了一个办法让它发挥作用。

首先,我添加了一个计时器

,然后每 1 秒检查

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
}

一次:)

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 :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文