列舉媒體專案
[與此頁面相關聯的功能Windows 媒體播放機 SDK是舊版功能。 它已被 MediaPlayer 取代。 MediaPlayer已針對Windows 10和Windows 11進行優化。 Microsoft 強烈建議新程式碼盡可能使用MediaPlayer,而不是Windows 媒體播放機 SDK。 Microsoft 建議盡可能重寫使用舊版 API 的現有程式碼,以使用新的 API。]
下列程式碼會顯示個別播放清單中包含的媒體專案。 當使用者按一下由 IDC_PLVIEW 識別的 ListView 控制項中的播放清單時,就會執行此程式碼。
STDMETHODIMP CSyncSettings::ShowMedia(long lIndex)
{
ATLASSERT(m_pMainDlg != NULL);
ATLASSERT(m_spPlaylist.p);
HRESULT hr = S_OK;
long lCount = 0; // Count of items in the playlist.
LVITEM lvI;
ZeroMemory(&lvI, sizeof(LVITEM));
lvI.mask = LVIF_TEXT;
CComPtr<IWMPMedia> spPlaylist; // Playlist the user selected.
CComBSTR bstrSourceURL; // The URL of a digital media file.
CComPtr<IWMPPlaylist> spNewPlaylist; // Temporary playlist that contains media items.
ULONG ulOnDevice = 0;
ULONG ulDidNotFit = 0;
HCURSOR hCursor = LoadCursor(NULL, IDC_WAIT);
HCURSOR hCursorOld = SetCursor(hCursor);
ListView_DeleteAllItems(m_hMediaView);
// Retrieve the playlist the user selected.
hr = m_spPlaylist->get_item(lIndex, &spPlaylist);
if(SUCCEEDED(hr) && spPlaylist)
{
// Retrieve the source URL (the path).
hr = spPlaylist->get_sourceURL(&bstrSourceURL);
}
if(SUCCEEDED(hr) && bstrSourceURL.Length())
{
CComPtr<IWMPCore3> spCore3;
m_spPlayer.QueryInterface(&spCore3);
// Create a temporary IWMPPlaylist object from the IWMPMedia
// playlist object.
hr = spCore3->newPlaylist(CComBSTR("Temp"), bstrSourceURL, &spNewPlaylist);
}
if(SUCCEEDED(hr) && spNewPlaylist)
{
hr = spNewPlaylist->get_count(&lCount);
}
// Walk the playlist.
if(SUCCEEDED(hr) && lCount > 0)
{
for(long i = 0; i < lCount; i++)
{
CComPtr<IWMPMedia> spMedia;
CComBSTR bstrMediaName;
CComBSTR bstrOnDevice = "???";
CComBSTR bstrFit = "???";
hr = spNewPlaylist->get_item(i, &spMedia);
if(SUCCEEDED(hr) && spMedia)
{
// Get the name.
hr = spMedia->get_name(&bstrMediaName);
}
if(SUCCEEDED(hr) && bstrMediaName.Length())
{
// Show the media name.
lvI.iItem = ListView_GetItemCount(m_hMediaView);
lvI.iSubItem = 0;
lvI.pszText = COLE2T(bstrMediaName);
ListView_InsertItem(m_hMediaView, &lvI);
// Retrieve the synchronization state information for
// the digital media file.
hr = GetPartnershipSyncState(spMedia, m_lCurrentPSIndex, &ulOnDevice, &ulDidNotFit);
}
if(SUCCEEDED(hr))
{
// Test whether the media is on the device.
if(ulOnDevice == 1)
{
bstrOnDevice = "Yes";
bstrFit = "Yes";
}
else
{
bstrOnDevice = "No";
// 1 means media did not fit,
// 0 means other reason for failure.
bstrFit = ulDidNotFit ? "No" : "Yes";
}
}
ListView_SetItemText(m_hMediaView, lvI.iItem, 1, COLE2T(bstrOnDevice));
ListView_SetItemText(m_hMediaView, lvI.iItem, 2, COLE2T(bstrFit));
}
}
if(SUCCEEDED(hr) && lCount == 0)
{
// Empty playlist.
lvI.iItem = ListView_GetItemCount(m_hMediaView);
lvI.iSubItem = 0;
lvI.pszText = COLE2T(CComBSTR("No items to display."));
ListView_InsertItem(m_hMediaView, &lvI);
}
SetCursor(hCursorOld);
return hr;
}
如需 GetPartnershipSyncState 函式的實作,請參閱 判斷播放清單同步處理狀態。
相關主題
意見反應
https://aka.ms/ContentUserFeedback。
即將推出:在 2024 年,我們將隨著內容的意見反應機制逐步淘汰 GitHub 問題,並以新的意見反應系統來取代。 如需詳細資訊,請參閱提交並檢視相關的意見反應