Partager via


Retrieving the Burn Status

[The feature associated with this page, Windows Media Player SDK, is a legacy feature. It has been superseded by MediaPlayer. MediaPlayer has been optimized for Windows 10 and Windows 11. Microsoft strongly recommends that new code use MediaPlayer instead of Windows Media Player SDK, when possible. Microsoft suggests that existing code that uses the legacy APIs be rewritten to use the new APIs if possible.]

In the code example that follows, the following dialog controls are defined:

Control ID Description
IDC_BURN_STATE Static text that represents the state of the CD burning operation.
IDC_PROGRESS Progress bar with a range of 0 to 100 that represents the total burn progress.
IDC_PROGRESS_TEXT Static text that represents the total burn progress as a number from 0 to 100.
IDC_AVAILABLE_TIME Static text to display the time available on the CD, in seconds.
IDC_FREE_SPACE Static text to display the free space on the CD, in bytes.
IDC_TOTAL_SPACE Static text to display the total capacity of the CD, in bytes.

 

You can monitor the progress of the burning operation by periodically calling IWMPCdromBurn::get_burnProgress while the CD is being burned. This method retrieves a progress value for the entire burning operation. The value retrieved is a number that represents the percentage of burning completed, from 0 to 100.

// Update the progress bar IDC_PROGRESS
// and the corresponding text string IDC_PROGRESS_TEXT.
long lProgress = 0;
hr = m_spCdromBurn->get_burnProgress(&lProgress);
if (SUCCEEDED(hr))
{
    SendMessage(GetDlgItem(IDC_PROGRESS),
        PBM_SETPOS, lProgress, 0);
    SetDlgItemInt(IDC_PROGRESS_TEXT, lProgress);
}

You can get the current state of the burning operation by calling IWMPCdromBurn::get_burnState. This method retrieves an enumeration specifying the current operation being performed.

// Retrieve the burn state.
WMPBurnState wmpbs = wmpbsUnknown;
HRESULT hr = m_spCdromBurn->get_burnState(&wmpbs);

if (SUCCEEDED(hr))
{
    // Set the burn state string.
    CComBSTR bstrState;
    switch (wmpbs)
    {
        case wmpbsUnknown:
        default:
            hr = bstrState.Append("Unknown state.");
            break;
        case wmpbsBusy:
            hr = bstrState.Append("Windows Media Player is Busy.");
            break;
        case wmpbsReady:
            hr = bstrState.Append("Ready to begin burning.");
            break;
        case wmpbsWaitingForDisc:
            hr = bstrState.Append("Waiting for disc.");
            break;
        case wmpbsRefreshStatusPending:
            hr = bstrState.Append("The burn playlist has changed.");
            m_spCdromBurn->refreshStatus();
            break;
        case wmpbsPreparingToBurn:
            hr = bstrState.Append("Preparing to burn the CD.");
            break;
        case wmpbsBurning:
            hr = bstrState.Append("The CD is being burned.");
            break;
        case wmpbsStopped:
            hr = bstrState.Append("The burning operation is stopped.");
            break;
        case wmpbsErasing:
            hr = bstrState.Append("Erasing the CD.");
            break;
    }
    if (SUCCEEDED(hr))
    {
        SetDlgItemTextW(IDC_BURN_STATE, bstrState.m_str);
    }
}

To retrieve the number of seconds of audio the CD can hold, call IWMPCdromBurn::getItemInfo with "AvailableTime" as the first parameter. The value retrieved by this function is represented by a string.

// Set "AvailableTime" string
CComBSTR bstrTime;
CComBSTR bstrItem;
HRESULT hr = bstrItem.Append("AvailableTime");
if (SUCCEEDED(hr))
{
    hr = m_spCdromBurn->getItemInfo(bstrItem, &bstrTime);
}
if (SUCCEEDED(hr))
{
    hr = bstrTime.Append(" seconds");
}
if (SUCCEEDED(hr))
{
    SetDlgItemTextW(IDC_AVAILABLE_TIME, bstrTime.m_str);
}

To retrieve the amount of free space on a disc, call IWMPCdromBurn::getItemInfo with "FreeSpace" as the first parameter. The value retrieved by this function is a string that represents the number of free bytes available on the disc.

// Set "FreeSpace" string
CComBSTR bstrFreeSpace;
CComBSTR bstrItem;
HRESULT hr = bstrItem.Append("FreeSpace");
if (SUCCEEDED(hr))
{
    hr = m_spCdromBurn->getItemInfo(bstrItem, &bstrFreeSpace);
}
if (SUCCEEDED(hr))
{
    hr = bstrFreeSpace.Append(" bytes");
}
if (SUCCEEDED(hr))
{
    SetDlgItemTextW(IDC_FREE_SPACE, bstrFreeSpace.m_str);
}

To retrieve the total capacity of a disc, call IWMPCdromBurn::getItemInfo with "TotalSpace" as the first parameter. The value retrieved by this function is a string that corresponds to the total number of bytes on the disc.

// Set "TotalSpace" string.
CComBSTR bstrTotalSpace;
CComBSTR bstrItem;
HRESULT hr = bstrItem.Append("TotalSpace");
if (SUCCEEDED(hr))
{
    hr = m_spCdromBurn->getItemInfo(bstrItem, &bstrTotalSpace);
}
if (SUCCEEDED(hr))
{
    hr = bstrTotalSpace.Append(" bytes");
}
if (SUCCEEDED(hr))
{
    SetDlgItemTextW(IDC_TOTAL_SPACE, bstrTotalSpace.m_str);
}

Burning a CD

Retrieving the CD Burning Interface

Starting the Burn Process

Erasing a Rewritable CD

Retrieving the Drive and Disc Status