Skip to content

Fix play button functionality (fixes #52) #58

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
40 changes: 37 additions & 3 deletions src/editorapp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,18 @@ EditorApp::EditorApp(QWidget *parent)
// Audio stuff
player = new QMediaPlayer(this);
player->setNotifyInterval(100);

// Set an explicit audio output to ensure playback works
QAudioDeviceInfo defaultOutputDevice = QAudioDeviceInfo::defaultOutputDevice();
if (defaultOutputDevice.isNull()) {
qWarning() << "No default audio output device found";
foreach (const QAudioDeviceInfo &deviceInfo, QAudioDeviceInfo::availableDevices(QAudio::AudioOutput)) {
qDebug() << "Available audio device:" << deviceInfo.deviceName();
defaultOutputDevice = deviceInfo;
break;
}
}

bufferPlayers[0] = new BufferPlayer(this);
bufferPlayers[1] = new BufferPlayer(this);

Expand Down Expand Up @@ -609,7 +621,7 @@ void EditorApp::on_actionLyricsToFile_triggered()
if (!fileName.isNull()) {
QFile f(fileName);
QFileInfo finfo(f); latestPath = finfo.path();
if (f.open(QFile::WriteOnly | QFile::Truncate)) {
if (f.open(QFile::WriteOnly | QIODevice::Truncate)) {
QTextStream out(&f);
out << noteGraph->dumpLyrics();
} else
Expand Down Expand Up @@ -967,11 +979,33 @@ void EditorApp::on_cmdPlay_clicked()
if (player) {
// Can't use currentMedia().isNull() because it will always return false after first set
if (player->currentMedia().canonicalUrl().isEmpty()) {
qDebug() << "No media loaded, opening media file dialog";
on_actionMusicFile_triggered();
} else {
if (player->state() == QMediaPlayer::PlayingState) player->pause();
else player->play();
qDebug() << "Media state:" << player->state() << "Media status:" << player->mediaStatus();
if (player->state() == QMediaPlayer::PlayingState) {
qDebug() << "Pausing playback";
player->pause();
} else {
qDebug() << "Starting playback";
// Make sure the player is ready before starting playback
if (player->mediaStatus() == QMediaPlayer::LoadedMedia ||
player->mediaStatus() == QMediaPlayer::BufferedMedia) {
player->play();
} else {
qDebug() << "Media not yet loaded, forcing reload and play";
// Try to explicitly reload the media
QUrl currentUrl = player->currentMedia().canonicalUrl();
player->setMedia(QMediaContent(currentUrl));
// Give it a short time to load before playing
QTimer::singleShot(100, [this]() {
player->play();
});
}
}
}
} else {
qDebug() << "Player is not initialized";
}
}

Expand Down