Bestimmen des Wiedergabelistensynchronisierungsstatus

Windows Media Player 10 oder höher verwendet das SyncState-Attribut, um Informationen darüber zu enthalten, ob eine bestimmte digitale Mediendatei auf ein portables Gerät kopiert wurde, und im Fall eines Fehlers, ob beim Kopieren ein Fehler aufgetreten ist, weil das Gerät nicht über genügend Arbeitsspeicher verfügt.

Der folgende Beispielcode erstellt eine Funktion, die diese Informationen aus einer digitalen Mediendatei abruft. Die Funktion verwendet die folgenden Parameter:

  • pMedia. Zeiger auf eine IWMPMedia-Schnittstelle, die die zu überprüfende digitale Mediendatei darstellt.
  • lPsIndex. Partnerschaftsindex des aktuellen Geräts.
  • pulOnDevice. Zeiger auf eine long-Variable, die den Wert empfängt, der angibt, ob die digitale Mediendatei auf das Gerät kopiert wurde.
  • pulDidNotFit. Zeiger auf eine long-Variable, die den Wert empfängt, der angibt, ob beim Kopiervorgang ein Fehler aufgetreten ist, weil das Gerät nicht über genügend Arbeitsspeicher verfügte.

Die im SyncState-Attribut enthaltenen Informationen werden bitweise codiert. Wie diese Funktion verwendet wird, erfahren Sie im Beispielcode unter Aufzählen der Medienelemente.

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;
}

IWMPMedia-Schnittstelle

IWMPMedia3::getItemInfoByType

Verwalten von Synchronisierungswiedergabelisten

SyncState-Attribut