IWMPMedia::setItemInfo 方法

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

setItemInfo 方法设置媒体项的指定属性的值。

语法

public void setItemInfo(
  System.String bstrItemName,
  System.String bstrVal
);

Public Sub setItemInfo( _
  ByVal bstrItemName As System.String, _
  ByVal bstrVal As System.String _
)
Implements IWMPMedia.setItemInfo

参数

bstrItemName [in]

作为属性名称的 System.String

bstrVal [in]

作为新值的 System.String

返回值

此方法不返回值。

备注

attributeCount 属性获取给定媒体项可用的属性数。 然后,索引号可以与 getAttributeName 方法一起使用,以确定可与此方法一起使用的内置属性的名称。

在使用此方法之前,请使用 isReadOnlyItem 方法发现是否可以设置特定属性。

在调用此方法之前,必须具有对库的完全访问权限。 有关详细信息,请参阅 库访问

注意

如果在应用程序中嵌入Windows 媒体播放器控件,则在用户运行Windows 媒体播放器之前,更改的文件属性不会写入数字媒体文件。

示例

以下示例使用 setItemInfo 更改当前媒体项的 Genre 属性的值。 文本框允许用户输入字符串,然后使用该字符串更改属性信息以响应按钮的 Click 事件。 AxWMPLib.AxWindowsMediaPlayer 对象由名为 player 的变量表示。

private void setNewGenre_Click(object sender, System.EventArgs e)
{
    // Store a WMPLib.IWMPMedia3 interface to the current media item. 
    WMPLib.IWMPMedia3 cm = (WMPLib.IWMPMedia3)player.currentMedia;

    // Get the user input from the TextBox. 
    string atValue = genText.Text;

    // Test for read-only status of the attribute. 
    if( cm.isReadOnlyItem("Genre") == false )
    {
        // Change the attribute value. 
        cm.setItemInfo("Genre", atValue);
    } 
}

Public Sub setNewGenre_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles setNewGenre.Click

    ' Store a WMPLib.IWMPMedia3 interface to the current media item. 
    Dim cm As WMPLib.IWMPMedia3 = player.currentMedia

    ' Get the user input from the TextBox. 
    Dim atValue = genText.Text

    ' Test for read-only status of the attribute. 
    If (cm.isReadOnlyItem("Genre") = False) Then

        ' Change the attribute value. 
        cm.setItemInfo("Genre", atValue)

    End If

End Sub

要求

要求
版本
Windows 媒体播放器 9 系列或更高版本
命名空间
WMPLib
程序集
Interop.WMPLib.dll (Interop.WMPLib.dll.dll)

另请参阅

IWMPMedia 接口 (VB 和 C#)

IWMPMedia.attributeCount (VB 和 C#)

IWMPMedia.getAttributeName (VB 和 C#)

IWMPMedia.isReadOnlyItem (VB 和 C#)