Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 播放音乐未播放最后两秒,直接切换到下一首 #409

Merged
merged 1 commit into from
Jul 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/music-player/core/vlc/MediaPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

#include <QDebug>

extern int g_playbackStatus;

typedef libvlc_media_player_t *(*vlc_media_player_new_function)(libvlc_instance_t *);
typedef libvlc_event_manager_t *(*vlc_media_player_event_manager_function)(libvlc_media_player_t *);
typedef void (*vlc_media_player_release_function)(libvlc_media_player_t *);
Expand Down Expand Up @@ -365,7 +367,14 @@ void VlcMediaPlayer::libvlc_callback(const libvlc_event_t *event,
emit core->backward();
break;
case libvlc_MediaPlayerEndReached:
emit core->end(); //play end
g_playbackStatus = 0;
if (core->_data.isEmpty()) {
emit core->end(); //play end
} else {
g_playbackStatus = 1;
// 设置当前进度时间、步进、总时间
emit core->endReached();
}
break;
case libvlc_MediaPlayerEncounteredError:
emit core->error();
Expand Down
4 changes: 4 additions & 0 deletions src/music-player/core/vlc/MediaPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,8 @@ public slots:
*/
void stateChanged();

void endReached();

protected:
static void libvlc_callback(const libvlc_event_t *event,
void *data);
Expand All @@ -298,6 +300,8 @@ public slots:
libvlc_event_manager_t *_vlcEvents;

VlcEqualizer *_vlcEqualizer;

QByteArray _data;
};

#endif // VLCQT_MEDIAPLAYER_H_
3 changes: 3 additions & 0 deletions src/music-player/core/vlc/sdlplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ SdlPlayer::SdlPlayer(VlcInstance *instance)
m_pCheckDataThread = new CheckDataZeroThread(this);
connect(m_pCheckDataThread, &CheckDataZeroThread::sigPlayNextSong, this, &SdlPlayer::checkDataZero, Qt::QueuedConnection);
connect(m_pCheckDataThread, &CheckDataZeroThread::sigExtraTime, this, &VlcMediaPlayer::timeChanged, Qt::QueuedConnection);
connect(this, &SdlPlayer::endReached, this, [=](){
m_pCheckDataThread->initTimeParams();
});
}
//}

Expand Down
2 changes: 1 addition & 1 deletion src/music-player/core/vlc/sdlplayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public slots:
SDL_AudioSpec obtainedAS;
bool m_loadSdlLibrary;

QByteArray _data;
// QByteArray _data;
int progressTag = 0;
int m_volume = 50.0;
bool m_mute = false;
Expand Down