Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
using iTunesLib;
using System;
using System.Threading;
namespace iTunesLibTest
{
class Program
{
static void Main(string[] args)
{
//iTunes COMのセットアップ
iTunesApp iTunes = new iTunesApp();
iTunes.OnPlayerPlayEvent += ITunes_OnPlayerPlayEvent;
while (true)
{
Thread.Sleep(1000);
}
}
//再生イベント時に呼び出されるメソッド
private static void ITunes_OnPlayerPlayEvent(object iTrack)
{
try
{
//再生中のトラック情報を取得
IITTrack track = (IITTrack)iTrack;
//アートワークコレクションを取得
IITArtworkCollection artworks = track.Artwork;
if (artworks == null || artworks.Count == 0)
{
Console.WriteLine("artwork not exists.");
return;
}
//ぶっちゃけアートワークは1個でいいので先頭だけを使用
IITArtwork a = null;
foreach (IITArtwork artwork in artworks)
{
a = artwork;
break;
}
//フォーマットに応じて保存先パスの拡張子を変更
String ext = null;
switch (a.Format)
{
case ITArtworkFormat.ITArtworkFormatJPEG:
ext = "jpg";
break;
case ITArtworkFormat.ITArtworkFormatPNG:
ext = "png";
break;
case ITArtworkFormat.ITArtworkFormatBMP:
ext = "bmp";
break;
case ITArtworkFormat.ITArtworkFormatUnknown:
Console.WriteLine("artwork is unknown format.");
return;
}
//アートワーク保存
String path = System.Environment.CurrentDirectory + "\\artwork." + ext;
Console.WriteLine("path=" + path);
a.SaveArtworkToFile(path);
}
catch (Exception e)
{
Console.WriteLine("Exception e=" + e);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.