Lendo valores de atributo de um CD ou DVD
[O recurso associado a esta página, Reprodutor Multimídia do Windows SDK, é um recurso herdado. Foi substituído pelo MediaPlayer. O MediaPlayer foi otimizado para Windows 10 e Windows 11. A Microsoft recomenda fortemente que o novo código use o MediaPlayer em vez de Reprodutor Multimídia do Windows SDK, quando possível. A Microsoft sugere que o código existente que usa as APIs herdadas seja reescrito para usar as novas APIs, se possível.]
Ao longo deste tópico, o objeto Player foi definido da seguinte maneira:
AxWMPLib.AxWindowsMediaPlayer Player;
using WMPLib;
O código de exemplo C# a seguir recupera os valores de todos os atributos no disco atual que está na unidade e os grava em um arquivo.
private void logDiscAttributes()
{
int iCDCount = 0; // Count of CD and DVD drives
int iAttrCount = 0; // Attribute count.
int iPLCount = 0; // Playlist item count.
IWMPCdromCollection cdCollection;
IWMPPlaylist playlist;
IWMPMedia media;
string strAttribName = "";
string strAttribValue = "";
string strText = "";
// Create a StreamWriter object to write
// the output to a file.
StreamWriter sw = new StreamWriter(strOutFile, true);
cdCollection = Player.cdromCollection;
iCDCount = cdCollection.count;
// Loop through the CD and DVD drives.
for (int i = 0; i < iCDCount; i++)
{
playlist = cdCollection.Item(i).Playlist;
// Loop through the playlist attributes.
iAttrCount = playlist.attributeCount;
for (int j = 0; j < iAttrCount; j++)
{
strText += "Playlist Attribute: \t";
strAttribName = playlist.get_attributeName(j);
strText += "\t" + strAttribName + "\t";
strAttribValue = playlist.getItemInfo(strAttribName);
strText += strAttribValue + "\n";
}
// Loop through the playlist.
iPLCount = playlist.count;
for (int k = 0; k < iPLCount; k++)
{
media = playlist.get_Item(k);
// Loop through the media attributes.
iAttrCount = media.attributeCount;
for (int m = 0; m < iAttrCount; m++)
{
strText += "Track or Chapter [" + m.ToString() + "]";
strAttribName = media.getAttributeName(m);
strText += "\t" + strAttribName + "\t";
strText += "Read Only: " + media.isReadOnlyItem(strAttribName) + "\t";
strAttribValue = media.getItemInfo(strAttribName);
strText += strAttribValue + "\n";
}
}
}
sw.Write(strText);
sw.Close();
MessageBox.Show(strOutFile + " created");
}
Tópicos relacionados
Comentários
https://aka.ms/ContentUserFeedback.
Em breve: Ao longo de 2024, eliminaremos os problemas do GitHub como o mecanismo de comentários para conteúdo e o substituiremos por um novo sistema de comentários. Para obter mais informações, consulteEnviar e exibir comentários de