Skip to content

Commit

Permalink
修正如果对媒体库右侧列表进行了排序,则播放曲目不正确的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
zhongyang219 committed Jul 11, 2024
1 parent ba5db30 commit 12e1124
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
3 changes: 1 addition & 2 deletions MusicPlayer2/AllMediaDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,7 @@ void CAllMediaDlg::OnOK()
//所有曲目使用媒体库模式播放
if (m_type == DT_ALL_MEDIA)
{
//TODO: 这里需要指定播放选中曲目
ok = CPlayer::GetInstance().SetMediaLibPlaylist(CMediaClassifier::CT_NONE, std::wstring());
ok = CPlayer::GetInstance().SetMediaLibPlaylist(CMediaClassifier::CT_NONE, std::wstring(), -1, songs.front(), true, true);
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion MusicPlayer2/MediaLibTabDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ void CMediaLibTabDlg::OnOK()
CMediaClassifier::ClassificationType type = GetClassificationType();
if (type != CMediaClassifier::CT_NONE)
{
ok = CPlayer::GetInstance().SetMediaLibPlaylist(type, GetClassificationItemName(), GetItemSelected(), true, true);
ok = CPlayer::GetInstance().SetMediaLibPlaylist(type, GetClassificationItemName(), -1, songs.front(), true, true);
}
else
{
Expand Down
13 changes: 10 additions & 3 deletions MusicPlayer2/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1172,7 +1172,7 @@ bool CPlayer::OpenASongInFolderMode(const SongInfo& song, bool play)
return true;
}

bool CPlayer::SetMediaLibPlaylist(CMediaClassifier::ClassificationType type, const std::wstring& name, int play_index, bool play, bool force)
bool CPlayer::SetMediaLibPlaylist(CMediaClassifier::ClassificationType type, const std::wstring& name, int play_index, const SongInfo& play_song, bool play, bool force)
{
if (!BeforeIniPlayList(!force))
return false;
Expand All @@ -1192,8 +1192,15 @@ bool CPlayer::SetMediaLibPlaylist(CMediaClassifier::ClassificationType type, con
m_index = playlistInfo.track;
m_current_position.fromInt(playlistInfo.position);
}
//指定了播放曲目
if (play_index >= 0)
//通过play_song指定了播放曲目
if (!play_song.IsEmpty())
{
m_current_song_tmp = play_song;
m_current_song_playing_tmp = play;
m_current_position.fromInt(0);
}
//通过play_index指定了播放曲目
else if (play_index >= 0)
{
m_index = play_index;
m_current_position.fromInt(0);
Expand Down
3 changes: 2 additions & 1 deletion MusicPlayer2/Player.h
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,9 @@ class CPlayer

//切换到媒体库模式
//play_index为-1表示按上次播放状态还原(默认为0),如果为大于等于0的值,则视为从头播放指定曲目; play用来设置是否立即播放
//play_song用于指定要播放的曲目,如果指定了play_song,则忽略play_index参数
//force为false时列表初始化完成后会尝试执行切换播放列表时继续播放
bool SetMediaLibPlaylist(CMediaClassifier::ClassificationType type, const std::wstring& name, int play_index = -1, bool play = false, bool force = false);
bool SetMediaLibPlaylist(CMediaClassifier::ClassificationType type, const std::wstring& name, int play_index = -1, const SongInfo& play_song = SongInfo(), bool play = false, bool force = false);

// 向当前播放列表添加文件,仅在播放列表模式可用,返回成功添加的数量(拒绝重复曲目)
// 由于cue解析问题,请在判断需要“添加歌曲”而不是“添加文件”时尽量使用CPlayer::AddSongs代替此方法而不是使用path构建SongInfo
Expand Down

0 comments on commit 12e1124

Please sign in to comment.