プレイリストと MediaCollection オブジェクト
[このページWindows メディア プレーヤー SDK に関連付けられている機能は、レガシ機能です。 MediaPlayer に置き換わりました。 MediaPlayer は、Windows 10とWindows 11用に最適化されています。 可能な場合は、新しいコードで SDK ではなく MediaPlayerWindows メディア プレーヤー使用することを強くお勧めします。 Microsoft は、レガシ API を使用する既存のコードを、可能であれば新しい API を使用するように書き換えるよう提案しています。]
MediaCollection オブジェクトを使用すると、さまざまな特別なプレイリストにアクセスでき、メタファイルから新しいプレイリストを作成するためのメソッドが含まれています。
次のメソッドは、特別なプレイリストを取得します。
- getAll
- getByAlbum
- getByAttribute
- getByAuthor
- getByGenre
- getByName
名前が示すように、これらのメソッドは、特定の条件に一致するライブラリ内のすべてのメディア項目を含むプレイリストを取得します。
MediaCollection を混同しないように注意してください。PlaylistCollection を使用する getByName メソッド。getByName メソッド。 MediaCollection メソッドは、指定した名前を持つすべてのメディア項目を含む Playlist オブジェクトを返します。 PlaylistCollection メソッドは、指定した名前を持つすべてのプレイリストを含む PlaylistArray オブジェクトを返します。
MediaCollection を使用できます。プレイリストとメディアアイテムをライブラリに追加するメソッドを追加します。 プレイリストを追加するには、プレイリストを定義するメタファイルへのパスを メソッドに渡します。 メソッドは常に Media オブジェクトを返します。 Media オブジェクトと Playlist オブジェクトの間でキャストすることはできません。 追加したプレイリストを操作するには、Media オブジェクトと同じ名前の Playlist オブジェクトを取得します。
次の C# の例では、 MediaCollection を使用して種類別にメディアを取得する方法を示します。getByAttribute メソッド。 このコードは、特定の型に関連付けられているすべての属性の名前と、それらの属性の読み取り/書き込みまたは読み取り専用の状態を取得します。 オーディオ、ビデオ、ラジオ、プレイリスト、その他、音楽、写真の種類の属性のリストを含む 1 つのファイルが生成されます。
string strOutFile = "AttribList.txt"; // Name of the output file
...
StreamWriter sw = new StreamWriter(strOutFile, true);
sw.Write(getMediaCollectionNames("Audio"));
sw.Write(getMediaCollectionNames("Video"));
sw.Write(getMediaCollectionNames("Radio"));
sw.Write(getMediaCollectionNames("Playlist"));
sw.Write(getMediaCollectionNames("Other"));
sw.Write(getMediaCollectionNames("Music"));
sw.Write(getMediaCollectionNames("Photo"));
sw.Close();
...
// The getMediaCollection method retrieves the names of
// all attributes for a specified type.
private string getMediaCollectionNames(string sSchema)
{
IWMPPlaylist playlist;
IWMPMedia media;
string strResult = ""; // Cumulative list of attributes
string strAttrName = ""; // Attribute name
string strReadWrite = ""; // Read/Write status of attribute
int iAttrCount = 0; // Count of playlist attributes
// Retrieve a playlist corresponding to the requested type.
playlist = Player.mediaCollection.getByAttribute("MediaType", sSchema);
// Initialize the result string
strResult += "\n" + sSchema.ToString() + " Schema: \n";
// Retrieve the attributes for the playlist
if (playlist.count != 0)
{
media = playlist.get_Item(0);
iAttrCount = media.attributeCount;
for (int i = 0; i < iAttrCount; i++)
{
strAttrName = media.getAttributeName(i);
strResult += " " + strAttrName +"\n";
if (media.isReadOnlyItem(strAttrName))
strReadWrite = "Read Only";
else
strReadWrite = "Read/Write";
strResult += " " + strReadWrite + "\n";
}
}
return strResult;
}
次の C# の例では、メタファイルからライブラリにプレイリストを追加する方法を示します。
// Add a playlist as a media item
IWMPMedia Media = Player.mediaCollection.add("c:\\testPlayList.asx");
静的プレイリストには、特定のメディア項目が含まれます。 自動プレイリストは、開かれるたびにライブラリを検索し、異なる時間に異なるメディアアイテムを含む可能性があります。 MediaCollection を使用して、ライブラリに静的プレイリストと自動再生リストの両方を追加できます。add メソッド。 PlaylistCollection を使用して静的プレイリストを追加することもできます。importPlaylist メソッド。
関連トピック
フィードバック
https://aka.ms/ContentUserFeedback」を参照してください。
以下は間もなく提供いたします。2024 年を通じて、コンテンツのフィードバック メカニズムとして GitHub の issue を段階的に廃止し、新しいフィードバック システムに置き換えます。 詳細については、「フィードバックの送信と表示