fix: don't use currentIndexChanged to load song
This commit is contained in:
parent
413711d073
commit
d28108f2e5
4
.github/workflows/windows.yml
vendored
4
.github/workflows/windows.yml
vendored
|
@ -39,10 +39,10 @@ jobs:
|
|||
:: ===== taglib =====
|
||||
git clone --recurse-submodules -q https://github.com/taglib/taglib.git dependencies_src/taglib
|
||||
cmake .\dependencies_src\taglib -Bbuild_dependencies/taglib -DBUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX="dependencies_bin" || goto :error
|
||||
cmake --build build_dependencies/taglib --config Release --target=install || goto :error
|
||||
cmake --build build_dependencies/taglib --config Release --target=install -j || goto :error
|
||||
:: ------ app ------
|
||||
cmake -Bbuild . -DCMAKE_INSTALL_PREFIX="%PWD%\build\" || goto :error
|
||||
cmake --build build --config Release || goto :error
|
||||
cmake --build build --config Release -j || goto :error
|
||||
cmake --build build --config Release --target=install
|
||||
:: ------ pkg ------
|
||||
windeployqt --verbose=2 --no-quick-import --no-translations --no-opengl-sw --no-system-d3d-compiler --no-system-dxc-compiler --multimedia --skip-plugin-types tls,networkinformation build\bin\pmusic.exe
|
||||
|
|
|
@ -45,15 +45,16 @@ set (EXE_NAME pmusic)
|
|||
file (GLOB PMUSIC_TS_FILES languages/*.ts)
|
||||
set (PMUSIC_CPP_FILES_FOR_I18N ${PMUSIC_CPP_FILES} ${PMUSIC_UI_FILES})
|
||||
|
||||
qt_create_translation(PMUSIC_QM_FILES ${PMUSIC_CPP_FILES_FOR_I18N} ${PMUSIC_TS_FILES})
|
||||
|
||||
add_executable(${EXE_NAME}
|
||||
${PMUSIC_HEADER_FILES}
|
||||
${PMUSIC_CPP_FILES}
|
||||
${PMUSIC_UI_FILES}
|
||||
resources.qrc
|
||||
)
|
||||
|
||||
${PMUSIC_QM_FILES}
|
||||
qt_add_translations(${EXE_NAME}
|
||||
TS_FILES
|
||||
${PMUSIC_TS_FILES}
|
||||
)
|
||||
|
||||
if (NOT TagLib_FOUND)
|
||||
|
@ -108,17 +109,3 @@ install (
|
|||
TARGETS ${EXE_NAME}
|
||||
${INSTALL_TARGETS_DEFAULT_ARGS}
|
||||
)
|
||||
|
||||
if (WIN32)
|
||||
set (QM_FILE_INSTALL_DIR "${CMAKE_INSTALL_BINDIR}/translations")
|
||||
else ()
|
||||
set (QM_FILE_INSTALL_DIR "${CMAKE_INSTALL_FULL_DATADIR}/pineapple-music/translations")
|
||||
target_compile_definitions(${EXE_NAME}
|
||||
PRIVATE QM_FILE_INSTALL_DIR=${QM_FILE_INSTALL_DIR}
|
||||
)
|
||||
endif ()
|
||||
|
||||
install (
|
||||
FILES ${PMUSIC_QM_FILES}
|
||||
DESTINATION ${QM_FILE_INSTALL_DIR}
|
||||
)
|
||||
|
|
10
main.cpp
10
main.cpp
|
@ -14,13 +14,9 @@ int main(int argc, char *argv[])
|
|||
QApplication a(argc, argv);
|
||||
|
||||
QTranslator translator;
|
||||
QString qmDir;
|
||||
#ifdef _WIN32
|
||||
qmDir = QDir(QCoreApplication::applicationDirPath()).absoluteFilePath("translations");
|
||||
#else
|
||||
qmDir = QT_STRINGIFY(QM_FILE_INSTALL_DIR);
|
||||
#endif
|
||||
translator.load(QString("pineapple-music_%1").arg(QLocale::system().name()), qmDir);
|
||||
if (translator.load(QLocale(), QLatin1String("pineapple-music"), QLatin1String("_"), QLatin1String(":/i18n"))) {
|
||||
a.installTranslator(&translator);
|
||||
}
|
||||
a.installTranslator(&translator);
|
||||
|
||||
// parse commandline arguments
|
||||
|
|
|
@ -58,6 +58,10 @@ void MainWindow::commandlinePlayAudioFiles(QStringList audioFiles)
|
|||
|
||||
if (!audioFileUrls.isEmpty()) {
|
||||
QModelIndex modelIndex = m_playlistManager->loadPlaylist(audioFileUrls);
|
||||
if (modelIndex.isValid()) {
|
||||
m_mediaPlayer->setSource(m_playlistManager->urlByIndex(modelIndex));
|
||||
play();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -190,7 +194,11 @@ void MainWindow::dropEvent(QDropEvent *e)
|
|||
return;
|
||||
}
|
||||
|
||||
m_playlistManager->loadPlaylist(urls);
|
||||
QModelIndex modelIndex = m_playlistManager->loadPlaylist(urls);
|
||||
if (modelIndex.isValid()) {
|
||||
m_mediaPlayer->setSource(m_playlistManager->urlByIndex(modelIndex));
|
||||
play();
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::loadFile()
|
||||
|
@ -205,6 +213,32 @@ void MainWindow::loadFile()
|
|||
}
|
||||
|
||||
m_playlistManager->loadPlaylist(urlList);
|
||||
m_mediaPlayer->setSource(urlList.first());
|
||||
}
|
||||
|
||||
void MainWindow::play()
|
||||
{
|
||||
QUrl fileUrl(m_mediaPlayer->source());
|
||||
|
||||
m_mediaPlayer->play();
|
||||
|
||||
ui->titleLabel->setText(fileUrl.fileName());
|
||||
ui->titleLabel->setToolTip(fileUrl.fileName());
|
||||
|
||||
if (fileUrl.isLocalFile()) {
|
||||
QString filePath(fileUrl.toLocalFile());
|
||||
QString suffix(filePath.mid(filePath.lastIndexOf('.') + 1));
|
||||
suffix = suffix.toUpper();
|
||||
|
||||
#ifndef NO_TAGLIB
|
||||
TagLib::FileRef fileRef(filePath.toLocal8Bit().data());
|
||||
|
||||
if (!fileRef.isNull() && fileRef.audioProperties()) {
|
||||
TagLib::AudioProperties *prop = fileRef.audioProperties();
|
||||
setAudioPropertyInfoForDisplay(prop->sampleRate(), prop->bitrate(), prop->channels(), suffix);
|
||||
}
|
||||
#endif // NO_TAGLIB
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::centerWindow()
|
||||
|
@ -228,7 +262,7 @@ void MainWindow::on_playBtn_clicked()
|
|||
{
|
||||
if (m_mediaPlayer->mediaStatus() == QMediaPlayer::NoMedia) {
|
||||
loadFile();
|
||||
m_mediaPlayer->play();
|
||||
play();
|
||||
} else if (m_mediaPlayer->mediaStatus() == QMediaPlayer::InvalidMedia) {
|
||||
ui->propLabel->setText("Error: InvalidMedia" + m_mediaPlayer->errorString());
|
||||
} else {
|
||||
|
@ -287,12 +321,18 @@ void MainWindow::on_playbackSlider_valueChanged(int value)
|
|||
|
||||
void MainWindow::on_prevBtn_clicked()
|
||||
{
|
||||
m_playlistManager->setCurrentIndex(m_playlistManager->previousIndex());
|
||||
QModelIndex index(m_playlistManager->previousIndex());
|
||||
m_playlistManager->setCurrentIndex(index);
|
||||
m_mediaPlayer->setSource(m_playlistManager->urlByIndex(index));
|
||||
play();
|
||||
}
|
||||
|
||||
void MainWindow::on_nextBtn_clicked()
|
||||
{
|
||||
m_playlistManager->setCurrentIndex(m_playlistManager->nextIndex());
|
||||
QModelIndex index(m_playlistManager->nextIndex());
|
||||
m_playlistManager->setCurrentIndex(index);
|
||||
m_mediaPlayer->setSource(m_playlistManager->urlByIndex(index));
|
||||
play();
|
||||
}
|
||||
|
||||
void MainWindow::on_volumeBtn_clicked()
|
||||
|
@ -336,27 +376,7 @@ void MainWindow::initConnections()
|
|||
}
|
||||
});
|
||||
connect(m_playlistManager, &PlaylistManager::currentIndexChanged, this, [=](int index){
|
||||
QUrl fileUrl(m_playlistManager->model()->urlByIndex(index));
|
||||
m_mediaPlayer->setSource(fileUrl);
|
||||
m_mediaPlayer->play();
|
||||
|
||||
ui->titleLabel->setText(fileUrl.fileName());
|
||||
ui->titleLabel->setToolTip(fileUrl.fileName());
|
||||
|
||||
if (fileUrl.isLocalFile()) {
|
||||
QString filePath(fileUrl.toLocalFile());
|
||||
QString suffix(filePath.mid(filePath.lastIndexOf('.') + 1));
|
||||
suffix = suffix.toUpper();
|
||||
|
||||
#ifndef NO_TAGLIB
|
||||
TagLib::FileRef fileRef(filePath.toLocal8Bit().data());
|
||||
|
||||
if (!fileRef.isNull() && fileRef.audioProperties()) {
|
||||
TagLib::AudioProperties *prop = fileRef.audioProperties();
|
||||
setAudioPropertyInfoForDisplay(prop->sampleRate(), prop->bitrate(), prop->channels(), suffix);
|
||||
}
|
||||
#endif // NO_TAGLIB
|
||||
}
|
||||
ui->playlistView->setCurrentIndex(m_playlistManager->model()->index(index));
|
||||
});
|
||||
|
||||
connect(m_mediaPlayer, &QMediaPlayer::positionChanged, this, [=](qint64 pos) {
|
||||
|
@ -458,5 +478,7 @@ void MainWindow::on_playListBtn_clicked()
|
|||
void MainWindow::on_playlistView_activated(const QModelIndex &index)
|
||||
{
|
||||
m_playlistManager->setCurrentIndex(index);
|
||||
m_mediaPlayer->setSource(m_playlistManager->urlByIndex(index));
|
||||
play();
|
||||
}
|
||||
|
||||
|
|
|
@ -47,6 +47,8 @@ protected:
|
|||
void dropEvent(QDropEvent *e) override;
|
||||
|
||||
void loadFile();
|
||||
void play();
|
||||
|
||||
void centerWindow();
|
||||
|
||||
private slots:
|
||||
|
|
Loading…
Reference in New Issue
Block a user