gpt4 book ai didi

c# - 我如何捕捉 iTunes 事件?

转载 作者:行者123 更新时间:2023-11-30 14:20:32 24 4
gpt4 key购买 nike

我已经添加了这段代码

        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;

}

关于c# - 我如何捕捉 iTunes 事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1236869/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com