同期プレイリストの列挙
[このページWindows メディア プレーヤー SDK に関連付けられている機能は、レガシ機能です。 MediaPlayer に置き換わりました。 MediaPlayer は、Windows 10とWindows 11用に最適化されています。 可能な場合は、新しいコードで SDK ではなく MediaPlayerWindows メディア プレーヤー使用することを強くお勧めします。 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 の issue を段階的に廃止し、新しいフィードバック システムに置き換えます。 詳細については、「フィードバックの送信と表示