枚举同步播放列表
[与此页面关联的功能(Windows 媒体播放器 SDK)是旧版功能。 它已被 MediaPlayer 取代。 MediaPlayer 已针对Windows 10和Windows 11进行了优化。 如果可能,Microsoft 强烈建议新代码使用 MediaPlayer 而不是 Windows 媒体播放器 SDK。 如果可能,Microsoft 建议重写使用旧 API 的现有代码以使用新 API。]
以下示例代码创建一个函数,该函数使用播放列表填充 ListView 控件。 同步播放列表首先显示。 当前所选设备的同步播放列表使用检查标记进行标记,并按同步优先级顺序排序。 所有其他播放列表均未选中。
ListView 控件配置为单选。 ListView 控件中播放列表的顺序决定了其同步优先级。 单个播放列表的选中状态决定了它是否是当前所选设备的同步播放列表。
参数 lPSIndex 指定当前所选便携式设备的合作关系索引。
STDMETHODIMP CSyncSettings::ShowPlaylists(long lPSIndex)
{
HRESULT hr = S_OK;
ATLASSERT(m_pMainDlg);
CComPtr<IWMPMediaCollection> spMediaCollection;
CComPtr<IWMPPlaylist> spPlaylist; // Contains a playlist of all playlists.
long lSyncItemCount= 0; // Count of items selected for synchronization.
ListView_DeleteAllItems(m_hPlView);
m_spPlaylist.Release();
if(lPSIndex == 0)
{
return S_OK;
}
HCURSOR hCursor = LoadCursor(NULL, IDC_WAIT);
HCURSOR hCursorOld = SetCursor(hCursor);
if(SUCCEEDED(hr))
{
// Retrieve a pointer to IWMPMediaCollection.
hr = m_spPlayer->get_mediaCollection(&spMediaCollection);
}
if(SUCCEEDED(hr) && spMediaCollection)
{
// Retrieve a playlist filled with IWMPMedia items.
// Each IWMPMedia represents an individual playlist
// in the library.
hr = spMediaCollection->getByAttribute(CComBSTR("MediaType"), CComBSTR("playlist"), &spPlaylist);
}
if(SUCCEEDED(hr) && spPlaylist)
{
// Get the sync attribute name for the current device.
CComBSTR bstrAttribute(g_szSyncAttributeNames[lPSIndex]);
// Sort the playlist.
// lSyncItemCount is the count of synchronization playlists.
hr = SortPlaylist(spPlaylist, bstrAttribute, &lSyncItemCount);
if(SUCCEEDED(hr))
{
m_spPlaylist = spPlaylist; // Cache the playlist.
long lCount = 0;
spPlaylist->get_count(&lCount);
// Fill the ListView control.
for(long i = 0; i < lCount; i++)
{
CComPtr<IWMPMedia> spMedia;
CComBSTR bstrPlaylistName;
CComBSTR bstrVal; // Value of the SyncXX attribute.
// Retrieve a playlist.
hr = spPlaylist->get_item(i, &spMedia);
if(SUCCEEDED(hr) && spMedia)
{
// Get the name.
hr = spMedia->get_name(&bstrPlaylistName);
}
if(SUCCEEDED(hr) && spMedia)
{
// Get the SyncXX attribute value.
hr = spMedia->getItemInfo(bstrAttribute, &bstrVal);
}
if(SUCCEEDED(hr) && bstrPlaylistName.Length())
{
// Insert the item in the ListView control.
LVITEM lvI;
ZeroMemory(&lvI, sizeof(LVITEM));
lvI.mask = LVIF_TEXT;
lvI.lParam = _wtol(bstrVal);
lvI.iItem = ListView_GetItemCount(m_hPlView);
lvI.pszText = "";
ListView_InsertItem(m_hPlView, &lvI);
// If this is a sync playlist, mark the check box.
if(i < lSyncItemCount)
{
ListView_SetCheckState(m_hPlView, i, TRUE);
}
// Display the playlist name.
lvI.iSubItem = 1;
lvI.pszText = COLE2T(bstrPlaylistName);
ListView_SetItem(m_hPlView, &lvI);
}
}
}
}
SetCursor(hCursorOld);
return hr;
}
有关 SortPlaylist 函数的实现,请参阅 按同步优先级对播放列表进行排序。
相关主题
反馈
https://aka.ms/ContentUserFeedback。
即将发布:在整个 2024 年,我们将逐步淘汰作为内容反馈机制的“GitHub 问题”,并将其取代为新的反馈系统。 有关详细信息,请参阅:提交和查看相关反馈