Retrieving the Rip 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.]
You can monitor the progress of the ripping operation by periodically calling IWMPCdromRip::get_ripProgress. This method retrieves a progress value for the entire ripping operation. The value retrieved is a number that represents the percentage of ripping completed, from 0 to 100.
The progress value represents the completed percentage of the entire ripping process. To determine the progress of a specific track, use IWMPMedia::getItemInfo with "RipProgress" as the attribute name. To determine the index of the track currently being ripped, call IWMPPlaylist::getItemInfo with "CurrentRipTrackIndex" as the attribute name.
You can monitor the state of the ripping operation by periodically calling IWMPCdromRip::get_ripState. This method retrieves a WMPRipState enumeration value that indicates whether the operation is in progress or stopped. You can also monitor the state of the ripping operation by handling the IWMPEvents3::CdromRipStateChange event. (See Handling Events in C++.) Be careful to compare the IWMPCdromRip pointer (provided by the event) to the pointer that represents your ripping operation, to ensure that the event was raised by your operation.
The following example code shows how to use these functions to retrieve the status of a ripping operation.
The following dialog controls are defined for the code example.
Control ID | Description |
---|---|
IDC_CURRENT_TRACK | Static text that represents the index of the track currently being ripped. |
IDC_TRACK_PROGRESS_TEXT | Static text that represents the progress of the track currently being ripped as a percentage. |
IDC_PROGRESS_TRACK | Progress bar with range 0 to 100 that represents the progress of the track currently being ripped as a percentage. |
IDC_OVERALL_PROGRESS_TEXT | Static text that represents the progress of the total ripping process as a percentage. |
IDC_PROGRESS_OVERALL | Progress bar with range 0 to 100 that represents the progress of the total ripping process as a percentage. |
IDC_RIP_STATE | Static text that displays the operation currently being performed ("Ripping", "Stopped", or "Unknown") |
HRESULT CMainDlg::UpdateStatus (void)
{
// bstrItemName and bstrVal are used for getItemInfo.
CComBSTR bstrItemName;
CComBSTR bstrVal;
// Get the current track index.
HRESULT hr = bstrItemName.Append("CurrentRipTrackIndex");
if (SUCCEEDED(hr))
{
hr = m_spPlaylist->getItemInfo(bstrItemName, &bstrVal);
}
// Update the dialog text with the track number.
if (SUCCEEDED(hr))
{
SetDlgItemTextW(IDC_CURRENT_TRACK, bstrVal.m_str);
}
// Get an IWMPMedia interface from the Playlist.
CComPtr<IWMPMedia> spMedia;
if (SUCCEEDED(hr))
{
long lIndex = _wtol(bstrVal.m_str);
hr = m_spPlaylist->get_item(lIndex, &spMedia);
}
// Update the current track progress bar and progress text.
if (SUCCEEDED(hr))
{
bstrItemName.Empty();
hr = bstrItemName.Append("RipProgress");
}
if (SUCCEEDED(hr))
{
hr = spMedia->getItemInfo(bstrItemName, &bstrVal);
}
if (SUCCEEDED(hr))
{
// Update the text corresponding to the percentage.
SetDlgItemTextW(IDC_TRACK_PROGRESS_TEXT, bstrVal.m_str);
// Obtain a numerical value from the progress string.
long lTrackPosition = _wtol(bstrVal.m_str);
// Update the progress bar showing the percentage.
SendMessage(GetDlgItem(IDC_PROGRESS_TRACK),
PBM_SETPOS, lTrackPosition, 0);
}
// Update the total progress bar and progress text.
long lTotalPosition = 0;
if (SUCCEEDED(hr))
{
hr = m_spCdromRip->get_ripProgress(&lTotalPosition);
}
if (SUCCEEDED(hr))
{
// Update the text corresponding to the percentage.
SetDlgItemInt(IDC_OVERALL_PROGRESS_TEXT, lTotalPosition);
// Update the progress bar showing the percentage.
SendMessage(GetDlgItem(IDC_PROGRESS_OVERALL),
PBM_SETPOS, lTotalPosition, 0);
}
// Update the ripping state.
CComBSTR bstrState;
WMPRipState wmprs = wmprsUnknown;
if (SUCCEEDED(hr))
{
hr = m_spCdromRip->get_ripState(&wmprs);
}
if (SUCCEEDED(hr))
{
switch (wmprs)
{
case wmprsUnknown:
default:
hr = bstrState.Append("Unknown");
break;
case wmprsRipping:
hr = bstrState.Append("Ripping");
break;
case wmprsStopped:
hr = bstrState.Append("Stopped");
break;
}
}
if (SUCCEEDED(hr))
{
SetDlgItemTextW(IDC_RIP_STATE, bstrState.m_str);
}
return hr;
}
Related topics