5294b7faf1
- Add fix-audio-CD-playing.patch to make Audio CD playback work - Add Set-vlcMedia-to-NULL-after-release.patch to prevent a crash when the Audio CD cannot be opened for some reason OBS-URL: https://build.opensuse.org/request/show/645276 OBS-URL: https://build.opensuse.org/package/show/KDE:Extra/kaffeine?expand=0&rev=39
223 lines
6.1 KiB
Diff
223 lines
6.1 KiB
Diff
From ef66906e3d3fda0144e18ed874c32266c1347ab1 Mon Sep 17 00:00:00 2001
|
|
From: Andrey Bychkov <mrdrew@altlinux.org>
|
|
Date: Fri, 26 Oct 2018 09:32:53 +0300
|
|
Subject: vlcmediawidget: fix audio CD playing
|
|
|
|
While here, also fix:
|
|
- all tracks playing
|
|
- 'next' & 'previous' working
|
|
---
|
|
src/backend-vlc/vlcmediawidget.cpp | 77 +++++++++++++++++++++++++++++++-------
|
|
src/backend-vlc/vlcmediawidget.h | 7 ++++
|
|
src/mediawidget.cpp | 4 +-
|
|
3 files changed, 72 insertions(+), 16 deletions(-)
|
|
|
|
diff --git a/src/backend-vlc/vlcmediawidget.cpp b/src/backend-vlc/vlcmediawidget.cpp
|
|
index fe320ae..568e9bc 100644
|
|
--- a/src/backend-vlc/vlcmediawidget.cpp
|
|
+++ b/src/backend-vlc/vlcmediawidget.cpp
|
|
@@ -27,6 +27,7 @@
|
|
#include <QMap>
|
|
#include <vlc/vlc.h>
|
|
#include <vlc/libvlc_version.h>
|
|
+#include <unistd.h>
|
|
|
|
#include "../configuration.h"
|
|
#include "vlcmediawidget.h"
|
|
@@ -279,6 +280,9 @@ void VlcMediaWidget::play(const MediaSource &source)
|
|
QByteArray url = source.getUrl().toEncoded();
|
|
playingDvd = false;
|
|
|
|
+ trackNumber = 1;
|
|
+ numDevType = 0;
|
|
+
|
|
switch (source.getType()) {
|
|
case MediaSource::Url:
|
|
if (url.endsWith(".iso")) {
|
|
@@ -287,6 +291,8 @@ void VlcMediaWidget::play(const MediaSource &source)
|
|
|
|
break;
|
|
case MediaSource::AudioCd:
|
|
+ numDevType=2;
|
|
+
|
|
if (url.size() >= 7) {
|
|
url.replace(0, 4, "cdda");
|
|
} else {
|
|
@@ -315,11 +321,24 @@ void VlcMediaWidget::play(const MediaSource &source)
|
|
break;
|
|
}
|
|
|
|
- libvlc_media_t *vlcMedia = libvlc_media_new_location(vlcInstance, url.constData());
|
|
+ typeOfDevice = url.constData();
|
|
+
|
|
+ vlcMedia = libvlc_media_new_location(vlcInstance, typeOfDevice);
|
|
+ if (numDevType == 2)
|
|
+ libvlc_media_add_option(vlcMedia, "cdda-track=1");
|
|
+
|
|
+ makePlay();
|
|
+
|
|
+ setCursor(Qt::BlankCursor);
|
|
+ setCursor(Qt::ArrowCursor);
|
|
+ timer->start(1000);
|
|
+ setMouseTracking(true);
|
|
+}
|
|
|
|
+void VlcMediaWidget::makePlay()
|
|
+{
|
|
if (vlcMedia == NULL) {
|
|
libvlc_media_player_stop(vlcMediaPlayer);
|
|
- qCWarning(logMediaWidget, "Cannot create media %s", qPrintable(source.getUrl().toDisplayString()));
|
|
return;
|
|
}
|
|
|
|
@@ -335,24 +354,46 @@ void VlcMediaWidget::play(const MediaSource &source)
|
|
libvlc_media_player_set_media(vlcMediaPlayer, vlcMedia);
|
|
libvlc_media_release(vlcMedia);
|
|
|
|
-// FIXME! subtitleUrl is only available for MediaSourceUrl private class
|
|
-// if (source.subtitleUrl.isValid())
|
|
-// setExternalSubtitle(source.subtitleUrl);
|
|
+ if (libvlc_media_player_play(vlcMediaPlayer) != 0)
|
|
+ return;
|
|
+}
|
|
|
|
- if (libvlc_media_player_play(vlcMediaPlayer) != 0) {
|
|
- qCWarning(logMediaWidget, "Cannot play media %s", qPrintable(source.getUrl().toDisplayString()));
|
|
- }
|
|
+void VlcMediaWidget::playDirection(int direction)
|
|
+{
|
|
+ char numBuff[256];
|
|
+ char strBuff[512] = "cdda-track=";
|
|
|
|
- setCursor(Qt::BlankCursor);
|
|
- setCursor(Qt::ArrowCursor);
|
|
- timer->start(1000);
|
|
- setMouseTracking(true);
|
|
+ if (direction == -1)
|
|
+ trackNumber--;
|
|
+ else
|
|
+ trackNumber++;
|
|
+
|
|
+ sprintf(numBuff, "%d", trackNumber);
|
|
+ strcat(strBuff, numBuff);
|
|
+
|
|
+ if (vlcMedia != NULL)
|
|
+ libvlc_media_release(vlcMedia);
|
|
+
|
|
+ vlcMedia = libvlc_media_new_location(vlcInstance, typeOfDevice);
|
|
+ libvlc_media_add_option(vlcMedia, strBuff);
|
|
+
|
|
+ makePlay();
|
|
+
|
|
+ sleep(1);
|
|
+
|
|
+ int playerState = libvlc_media_player_get_state(vlcMediaPlayer);
|
|
+
|
|
+ if (playerState != libvlc_Playing)
|
|
+ stop();
|
|
}
|
|
|
|
void VlcMediaWidget::stop()
|
|
{
|
|
libvlc_media_player_stop(vlcMediaPlayer);
|
|
|
|
+ if (trackNumber != 1)
|
|
+ trackNumber = 1;
|
|
+
|
|
timer->stop();
|
|
setCursor(Qt::BlankCursor);
|
|
setCursor(Qt::ArrowCursor);
|
|
@@ -452,7 +493,10 @@ bool VlcMediaWidget::jumpToPreviousChapter()
|
|
{
|
|
int currentTitle = libvlc_media_player_get_title(vlcMediaPlayer);
|
|
int currentChapter = libvlc_media_player_get_chapter(vlcMediaPlayer);
|
|
- libvlc_media_player_previous_chapter(vlcMediaPlayer);
|
|
+ if (numDevType == 2)
|
|
+ playDirection(-1);
|
|
+ else
|
|
+ libvlc_media_player_previous_chapter(vlcMediaPlayer);
|
|
|
|
if ((libvlc_media_player_get_title(vlcMediaPlayer) != currentTitle) ||
|
|
(libvlc_media_player_get_chapter(vlcMediaPlayer) != currentChapter)) {
|
|
@@ -466,7 +510,10 @@ bool VlcMediaWidget::jumpToNextChapter()
|
|
{
|
|
int currentTitle = libvlc_media_player_get_title(vlcMediaPlayer);
|
|
int currentChapter = libvlc_media_player_get_chapter(vlcMediaPlayer);
|
|
- libvlc_media_player_next_chapter(vlcMediaPlayer);
|
|
+ if (numDevType == 2)
|
|
+ playDirection(1);
|
|
+ else
|
|
+ libvlc_media_player_next_chapter(vlcMediaPlayer);
|
|
|
|
if ((libvlc_media_player_get_title(vlcMediaPlayer) != currentTitle) ||
|
|
(libvlc_media_player_get_chapter(vlcMediaPlayer) != currentChapter)) {
|
|
@@ -507,6 +554,8 @@ int VlcMediaWidget::updatePlaybackStatus()
|
|
playbackStatus = MediaWidget::Paused;
|
|
break;
|
|
case libvlc_Ended:
|
|
+ playDirection(1);
|
|
+ break;
|
|
case libvlc_Error:
|
|
playbackStatus = MediaWidget::Idle;
|
|
// don't keep last picture shown
|
|
diff --git a/src/backend-vlc/vlcmediawidget.h b/src/backend-vlc/vlcmediawidget.h
|
|
index 785370d..1534ed0 100644
|
|
--- a/src/backend-vlc/vlcmediawidget.h
|
|
+++ b/src/backend-vlc/vlcmediawidget.h
|
|
@@ -25,6 +25,7 @@
|
|
|
|
class libvlc_event_t;
|
|
class libvlc_instance_t;
|
|
+class libvlc_media_t;
|
|
class libvlc_media_player_t;
|
|
class QTimer;
|
|
|
|
@@ -68,6 +69,8 @@ public:
|
|
bool jumpToNextChapter();
|
|
void showDvdMenu();
|
|
void dvdNavigate(int key);
|
|
+ void playDirection(int direction);
|
|
+ void makePlay();
|
|
|
|
int updatePlaybackStatus();
|
|
void updateCurrentTotalTime();
|
|
@@ -90,10 +93,14 @@ private:
|
|
static void vlcEventHandler(const libvlc_event_t *event, void *instance);
|
|
|
|
libvlc_instance_t *vlcInstance;
|
|
+ libvlc_media_t *vlcMedia;
|
|
libvlc_media_player_t *vlcMediaPlayer;
|
|
bool playingDvd;
|
|
bool mouseVisible;
|
|
QMap<int, int> subtitleId;
|
|
+ QByteArray typeOfDevice;
|
|
+ int numDevType;
|
|
+ int trackNumber = 1;
|
|
};
|
|
|
|
#endif /* VLCMEDIAWIDGET_H */
|
|
diff --git a/src/mediawidget.cpp b/src/mediawidget.cpp
|
|
index fd84d87..f38d301 100644
|
|
--- a/src/mediawidget.cpp
|
|
+++ b/src/mediawidget.cpp
|
|
@@ -793,14 +793,14 @@ void MediaWidget::previous()
|
|
{
|
|
if (source->getType() == MediaSource::Url)
|
|
emit playlistPrevious();
|
|
- source->previous();
|
|
+ backend->jumpToPreviousChapter();
|
|
}
|
|
|
|
void MediaWidget::next()
|
|
{
|
|
if (source->getType() == MediaSource::Url)
|
|
emit playlistNext();
|
|
- source->next();
|
|
+ backend->jumpToNextChapter();
|
|
}
|
|
|
|
void MediaWidget::stop()
|
|
--
|
|
cgit v0.11.2
|
|
|