This commit is contained in:
zhongyang219
2021-10-22 13:20:48 +08:00
parent 9e4952295a
commit 2608d359c1
3 changed files with 27 additions and 23 deletions
+4 -1
View File
@@ -365,6 +365,7 @@ void CBassCore::Close()
void CBassCore::Play()
{
m_playing_state = PS_PLAYING;
if (theApp.m_play_setting_data.fade_effect && theApp.m_play_setting_data.fade_time > 0) //如果设置了播放时音量淡入淡出
{
KillTimer(theApp.m_pMainWnd->GetSafeHwnd(), FADE_TIMER_ID);
@@ -386,6 +387,7 @@ void CBassCore::Play()
void CBassCore::Pause()
{
m_playing_state = PS_PAUSED;
if (theApp.m_play_setting_data.fade_effect && theApp.m_play_setting_data.fade_time > 0) //如果设置了播放时音量淡入淡出
{
BASS_ChannelSlideAttribute(m_musicStream, BASS_ATTRIB_VOL, 0, theApp.m_play_setting_data.fade_time); //音量渐变到0
@@ -405,6 +407,7 @@ void CBassCore::Pause()
void CBassCore::Stop()
{
m_playing_state = PS_STOPED;
DWORD playing_state = BASS_ChannelIsActive(m_musicStream);
if (theApp.m_play_setting_data.fade_effect && theApp.m_play_setting_data.fade_time > 0 && playing_state == BASS_ACTIVE_PLAYING)
{
@@ -446,7 +449,7 @@ bool CBassCore::SongIsOver()
bool is_over{ (m_last_playing_state == BASS_ACTIVE_PLAYING && state == BASS_ACTIVE_STOPPED)
|| m_error_code == BASS_ERROR_ENDED };
m_last_playing_state = state;
return is_over;
return is_over && m_playing_state == PS_PLAYING && m_musicStream != 0;
}
int CBassCore::GetCurPosition()
+1
View File
@@ -103,4 +103,5 @@ private:
enum { FADE_TIMER_ID = 1010 };
static CCriticalSection m_critical;
PlayingState m_playing_state{};
};
+22 -22
View File
@@ -577,31 +577,31 @@ bool CPlayer::SongIsOver() const
}
else
{
//return m_pCore->SongIsOver();
return m_pCore->SongIsOver();
bool song_is_over{ false };
static int last_pos;
if ((m_playing == PS_PLAYING && m_current_position.toInt() == last_pos && m_current_position.toInt() != 0 //如果正在播放且当前播放的位置没有发生变化且当前播放位置不为0,
&& m_current_position.toInt() > m_song_length.toInt() - 1000) //且播放进度到了最后1秒
|| m_error_code == BASS_ERROR_ENDED) //或者出现BASS_ERROR_ENDED错误,则判断当前歌曲播放完了
//有时候会出现识别的歌曲长度超过实际歌曲长度的问题,这样会导致歌曲播放进度超过实际歌曲结尾时会出现BASS_ERROR_ENDED错误,
//检测到这个错误时直接判断歌曲已经播放完了。
song_is_over = true;
//static int progress_no_change_cnt{};
//if (m_current_position.toInt() == last_pos)
// progress_no_change_cnt++;
//else
// progress_no_change_cnt = 0;
//if (m_playing == 2 && progress_no_change_cnt > 10) //如果正在播放而且播放进度连续指定次数都没有变化,也判断歌曲播放完了。
//bool song_is_over{ false };
//static int last_pos;
//if ((m_playing == PS_PLAYING && m_current_position.toInt() == last_pos && m_current_position.toInt() != 0 //如果正在播放且当前播放的位置没有发生变化且当前播放位置不为0,
// && m_current_position.toInt() > m_song_length.toInt() - 1000) //且播放进度到了最后1秒
// || m_error_code == BASS_ERROR_ENDED) //或者出现BASS_ERROR_ENDED错误,则判断当前歌曲播放完了
////有时候会出现识别的歌曲长度超过实际歌曲长度的问题,这样会导致歌曲播放进度超过实际歌曲结尾时会出现BASS_ERROR_ENDED错误,
////检测到这个错误时直接判断歌曲已经播放完了。
// song_is_over = true;
last_pos = m_current_position.toInt();
return song_is_over;
//这里本来直接使用return current_position_int>=m_song_length_int来判断歌曲播放完了,
//但是BASS音频库在播放时可能会出现当前播放位置一直无法到达歌曲长度位置的问题,
//这样函数就会一直返回false。
////static int progress_no_change_cnt{};
////if (m_current_position.toInt() == last_pos)
//// progress_no_change_cnt++;
////else
//// progress_no_change_cnt = 0;
////if (m_playing == 2 && progress_no_change_cnt > 10) //如果正在播放而且播放进度连续指定次数都没有变化,也判断歌曲播放完了。
//// song_is_over = true;
//last_pos = m_current_position.toInt();
//return song_is_over;
////这里本来直接使用return current_position_int>=m_song_length_int来判断歌曲播放完了,
////但是BASS音频库在播放时可能会出现当前播放位置一直无法到达歌曲长度位置的问题,
////这样函数就会一直返回false。
}
}