我已添加此代码
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;
}