IWMPPlaylistCollection::getByName 方法

[與此頁面相關聯的功能Windows 媒體播放機 SDK是舊版功能。 MediaPlayer已取代它。 MediaPlayer已針對Windows 10和Windows 11進行優化。 Microsoft 強烈建議新程式碼盡可能使用MediaPlayer,而不是Windows 媒體播放機 SDK。 Microsoft 建議使用舊版 API 的現有程式碼盡可能重寫為使用新的 API。

getByName方法會傳回IWMPPlaylistArray介面,如果有任何存在,即可存取具有指定名稱的播放清單。

語法

public IWMPPlaylistArray getByName(
  System.String bstrName
);

Public Function getByName( _
  ByVal bstrName As System.String _
) As IWMPPlaylistArray
Implements IWMPPlaylistCollection.getByName

參數

bstrName [in]

System.String,這是播放清單的名稱。

傳回值

已擷取播放清單陣列的 WMPLib.IWMPPlaylistArray 介面。

備註

使用 IWMPPlaylistArray.count 來判斷播放清單是否存在。 如果 count 為零,則陣列是空的。

呼叫此方法之前,您必須擁有程式庫的讀取權限。 如需詳細資訊,請參閱 程式庫存取

範例

下列範例會使用getByName來檢查播放清單集合中名為 「Favorites -- 4 和 5 star rated」 的播放清單集合。 如果依該名稱的播放清單存在, getByName 會將它設定為目前的播放清單。 AxWMPLib.AxWindowsMediaPlayer物件是由名為 player 的變數表示。

// Get the count of the playlists named "Favorites -- 4 and 5 star rated".
int checkit = player.playlistCollection.getByName("Favorites -- 4 and 5 star rated").count;

// Since duplicate playlist names are allowed, the count returned
// will be either zero (no playlist) or greater than zero (playlist exists).
if (checkit > 0)
{
    // Retrieve a playlist array containing "Favorites -- 4 and 5 star rated".
    // Assume that there is only one playlist with that name, and assign it to the 
    // current playlist.
    player.currentPlaylist = player.playlistCollection.getByName("Favorites -- 4 and 5 star rated").Item(0);
}

'  Get the count of the playlists named "Favorites -- 4 and 5 star rated".
Dim checkit As Integer = player.playlistCollection.getByName("Favorites -- 4 and 5 star rated").count

'  Since duplicate playlist names are allowed, the count returned
'  will be either zero (no playlist) or greater than zero (playlist exists).
If (checkit > 0) Then

    '  Retrieve a playlist array object containing "Favorites -- 4 and 5 star rated".
    '  Assume that there is only one playlist with that name, and assign it to the 
    '  current playlist.
    player.currentPlaylist = player.playlistCollection.getByName("Favorites -- 4 and 5 star rated").Item(0)

End If

規格需求

需求
版本
Windows Media Player  9  系列或更新的版本。
命名空間
WMPLib
組件
Interop.WMPLib.dll (Interop.WMPLib.dll.dll)

另請參閱

IWMPPlaylistArray 介面 (VB 和 C#)

IWMPPlaylistArray.count (VB 和 C#)

IWMPPlaylistCollection 介面 (VB 和 C#)