コード例 #1
0
BOOL CQuizRunningDlg::DisplayNextQuestion()
{
	TRACEST(_T("CQuizRunningDlg::DisplayNextQuestion"));
	PrgAPI* pAPI = PRGAPI();
	ActionManager* pAM = pAPI->GetActionManager();
	TracksFilter tf;
	tf.Duration.match = NUMM_Over;
	tf.Duration.val = 30;
	FullTrackRecordCollection col;
	if (!pAM->GetRandomTrackCollection(col, tf, 4))
		return FALSE;
	UINT trackLength = 0;
	TCHAR trackPath[MAX_PATH];
	m_correctAnswer = INT((rand() * 4) / RAND_MAX);
	FullTrackRecordSP rec;
	for (int i = 0; i < 4; i++)
	{
		TCHAR txt[1000];
		_sntprintf(txt, 1000, _T("%d. %s - %s"), i + 1, col[i]->artist.name.c_str(),col[i]->track.name.c_str());
		m_pButtons[i + BT_Answer1]->SetWindowText(txt);
		if (m_correctAnswer == i)
		{
			_tcsncpy(trackPath, col[i]->track.location.c_str(), MAX_PATH);
			trackLength = col[i]->track.duration;
		}
		m_pButtons[i + BT_Answer1]->ShowWindow(TRUE);
	}

	m_subTitle.SetWindowText(PRGAPI()->GetString(IDS_RECOGNISESONG));
	if (!m_pPlayer->Play(trackPath))
	{
		TRACE(_T("@1CQuizRunningDlg::DisplayNextQuestion. Cannot play the file '%s'\r\n"), trackPath);
		return FALSE;
	}
	m_pPlayer->Pause();
	trackLength = INT(m_pPlayer->GetMediaLength());
	if (trackLength < 20)
	{
		TRACE(_T("@1CQuizRunningDlg::DisplayNextQuestion. trackLength is %d '%s'\r\n"), trackLength, trackPath);
		return FALSE;
	}
	m_subTitle.SetColor(CLabelEx::COL_Text, RGB(200,200,200));
	UINT startSec = (trackLength - 40) * rand() / RAND_MAX + 20;//Select 20sec in the track after the first 20 sec
	m_pPlayer->SetVolume(95);
	m_pPlayer->SetMediaPos((DOUBLE) startSec);


	return TRUE;
}