MediaCollection.getByName 方法

[与此页面关联的功能(Windows 媒体播放器 SDK)是旧版功能。 它已被 MediaPlayer 取代。 MediaPlayer 已针对Windows 10和Windows 11进行了优化。 Microsoft 强烈建议新代码尽可能使用 MediaPlayer 而不是 Windows 媒体播放器 SDK。 如果可能,Microsoft 建议重写使用旧 API 的现有代码以使用新 API。]

getByName 方法检索具有指定名称的媒体项的播放列表。

语法

retVal = MediaCollection.getByName(
  name
)

参数

name [in]

包含名称的字符串

返回值

此方法返回 一个 Playlist 对象。

备注

若要使用此方法,需要对库的读取访问权限。 有关详细信息,请参阅 库访问

示例

以下 JScript 示例使用 MediaCollectiongetByName 从库中检索三个项。 然后,每个项目将追加到当前播放列表。 Player 对象是使用 ID=“Player”创建的。

// In each case, use the name exactly as it appears in the library.
// Windows Media Player does not include file name extensions or file paths
// in the name. Internet URLs include the entire path, but not the 
// file name extension.

// Get a playlist object that contains an Internet URL.
var One = Player.mediaCollection.getByName("https://www.proseware.com/Media/Laure");
 
// Get a playlist object that contains a file on a network server.
var Two = Player.mediaCollection.getByName("Jeanne");

// Get a playlist object that contains a file on a local drive.
var Three = Player.mediaCollection.getByName("house");

// Append each item to the current playlist. Since each playlist retrieved
// using getByName contains one digital media item, use Playlist.item with
// an index of zero to reference that item.
Player.currentPlaylist.appendItem(One.item(0));
Player.currentPlaylist.appendItem(Two.item(0));
Player.currentPlaylist.appendItem(Three.item(0));

要求

要求
版本
Windows 媒体播放器版本 7.0 或更高版本。
DLL
Wmp.dll

另请参阅

MediaCollection 对象

Playlist 对象

Settings.mediaAccessRights

Settings.requestMediaAccessRights