判斷播放清單同步處理狀態
[與此頁面相關聯的功能Windows 媒體播放機 SDK是舊版功能。 它已被 MediaPlayer 取代。 MediaPlayer已針對Windows 10和Windows 11進行優化。 Microsoft 強烈建議新程式碼盡可能使用MediaPlayer,而不是Windows 媒體播放機 SDK。 Microsoft 建議盡可能重寫使用舊版 API 的現有程式碼,以使用新的 API。]
Windows 媒體播放機 10 或更新版本會使用SyncState屬性來包含特定數位媒體檔案是否已複製到可攜式裝置的相關資訊,並在失敗的情況下,是否因為裝置沒有足夠的記憶體而複製失敗。
下列範例程式碼會建立函式,以從數位媒體檔案擷取這項資訊。 函式會採用下列參數:
- pMedia。 IWMPMedia介面的指標,代表要檢查的數位媒體檔案。
- lPsIndex。 目前裝置的合作關係索引。
- pulOnDevice。 長變數的指標,這個變數會接收值,指出數位媒體檔案是否已複製到裝置。
- pulDidNotFit。 長 變數的 指標,這個變數會接收指出複製作業是否失敗,因為裝置沒有足夠的記憶體。
SyncState屬性中包含的資訊會以位方式編碼。 您可以在 列舉媒體專案中的範例程式碼中查看此函式的使用方式。
STDMETHODIMP CSyncSettings::GetPartnershipSyncState(IWMPMedia* pMedia, long lPsIndex, ULONG *pulOnDevice, ULONG *pulDidNotFit)
{
ATLASSERT(pMedia);
ATLASSERT(lPsIndex > 0 &&
lPsIndex < 17);
ATLASSERT(pulOnDevice);
ATLASSERT(pulDidNotFit);
CComVariant varSyncStateVal;
CComPtr<IWMPMedia> spMedia(pMedia);
CComPtr<IWMPMedia3> spMedia3;
HRESULT hr = spMedia.QueryInterface(&spMedia3);
ULONG ulSyncState = 0; // Stores the ulVal member of varSyncStateVal.
ULONG lLSB = 0; // Represents least significant bit: Did the media fail to copy because it would not fit?
ULONG lMSB = 0; // Represents most significant bit: Is the media on the device?
// Calculate the bit shift required to isolate the partnership bit
// pair from the SyncState attribute.
const int iRshift = (lPsIndex - 1) * 2;
if(SUCCEEDED(hr) && spMedia3)
{
hr = spMedia3->getItemInfoByType(CComBSTR("SyncState"), CComBSTR(""), 0, &varSyncStateVal);
}
if(SUCCEEDED(hr) && varSyncStateVal.vt == VT_UI4)
{
// Get the value.
ulSyncState = varSyncStateVal.ulVal;
// Shift the bit pair to the rightmost position.
ulSyncState >>= iRshift;
// Mask the rightmost bit pair.
ulSyncState &= 3;
// Get the LSB
lLSB = ulSyncState & ~2; // Sets the 2E1 bit to zero.
// Get the MSB
ulSyncState >>= 1;
lMSB = ulSyncState;
}
// Return the bits.
*pulOnDevice = lMSB;
*pulDidNotFit = lLSB;
return hr;
}
相關主題
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應