按同步优先级对播放列表进行排序
[与此页面关联的功能(Windows 媒体播放器 SDK)是旧版功能。 它已被 MediaPlayer 取代。 MediaPlayer 已针对Windows 10和Windows 11进行了优化。 如果可能,Microsoft 强烈建议新代码使用 MediaPlayer 而不是 Windows 媒体播放器 SDK。 如果可能,Microsoft 建议重写使用旧 API 的现有代码以使用新 API。]
以下代码执行一种简单的播放列表。 可以在 枚举同步播放列表中的示例代码中查看此函数的用法。 函数采用以下参数:
- pPlaylist。 指向要排序的Windows 媒体播放器播放列表的指针。 播放列表中的媒体项必须指向其他播放列表,而不是单个数字媒体文件。
- bstrSyncAttribute。 包含当前设备的同步合作关系属性名称的 BSTR, (“Sync01”、“Sync02”等) 。
- plSelected。 指向接收同步播放列表计数的 长 变量的指针。
函数检查每个媒体项的同步合作关系属性, (表示 pPlaylist 指定的播放列表) 播放列表。 如果 属性具有非零值,则代码会将媒体项移动到播放列表的开头,并按优先级顺序插入它。
完成后,函数将返回同步播放列表 (同步播放列表) 具有非零值的媒体项计数。
STDMETHODIMP CSyncSettings::SortPlaylist(IWMPPlaylist *pPlaylist, BSTR bstrSyncAttribute, long *plSelected)
{
HRESULT hr = S_OK;
long lSyncItemCount = 0;
ATLASSERT (pPlaylist);
ATLASSERT (plSelected);
// Local copies of the parameters.
CComPtr<IWMPPlaylist> spPlaylist(pPlaylist);
CComBSTR bstrAttribute(bstrSyncAttribute);
ATLASSERT (bstrAttribute.Length());
// Get the count of playlist media items.
long lCount = 0;
spPlaylist->get_count(&lCount);
// Walk the playlist.
for(long i = 0; i < lCount; i++)
{
CComPtr<IWMPMedia> spMedia;
CComBSTR bstrVal;
long lPriority = 0;
hr = spPlaylist->get_item(i, &spMedia);
if(SUCCEEDED(hr) && spMedia)
{
// Get the sync priority value as a string.
hr = spMedia->getItemInfo(bstrAttribute, &bstrVal);
}
if(SUCCEEDED(hr) && spMedia)
{
// Convert sync priority to a long number.
lPriority = _wtol(bstrVal);
}
// Sort the playlist.
// Only move the current item if it has a
// sync priority value.
if(lPriority > 0)
{
lSyncItemCount++;
// Walk down the list and insert the item
// in ascending order.
for(long j = 0; j < lCount; j++)
{
CComPtr<IWMPMedia> spMediaCompare;
CComBSTR bstrValCompare;
long lPriorityTest = 0;
hr = spPlaylist->get_item(j, &spMediaCompare);
if(SUCCEEDED(hr) && spMediaCompare.p)
{
hr = spMediaCompare->getItemInfo(bstrAttribute, &bstrValCompare);
}
if(SUCCEEDED(hr) && spMediaCompare.p)
{
lPriorityTest = _wtol(bstrValCompare);
if(lPriority <= lPriorityTest ||
0 == lPriorityTest)
{
hr = spPlaylist->moveItem(i, j);
break;
}
}
} // for j
} // if(lPriority > 0)
} // for i
// Return the sync item count.
*plSelected = lSyncItemCount;
return hr;
}
相关主题
反馈
https://aka.ms/ContentUserFeedback。
即将发布:在整个 2024 年,我们将逐步淘汰作为内容反馈机制的“GitHub 问题”,并将其取代为新的反馈系统。 有关详细信息,请参阅:提交和查看相关反馈