[vlc-commits] qt: video progress is stored as precentage in the medialibrary, not a time
Pierre Lamot
git at videolan.org
Fri Jan 10 15:06:14 CET 2020
vlc | branch: master | Pierre Lamot <pierre at videolabs.io> | Thu Jan 9 11:37:57 2020 +0100| [c857406229a807afb6ef706eedae1a24f4d37769] | committer: Jean-Baptiste Kempf
qt: video progress is stored as precentage in the medialibrary, not a time
Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=c857406229a807afb6ef706eedae1a24f4d37769
---
.../gui/qt/medialibrary/mlrecentsvideomodel.cpp | 4 --
modules/gui/qt/medialibrary/mlvideo.cpp | 53 +++++++++++++---------
modules/gui/qt/medialibrary/mlvideo.hpp | 14 +++---
modules/gui/qt/medialibrary/mlvideomodel.cpp | 4 --
modules/gui/qt/medialibrary/qml/VideoGridItem.qml | 3 +-
.../gui/qt/medialibrary/qml/VideoListDisplay.qml | 2 +-
6 files changed, 40 insertions(+), 40 deletions(-)
diff --git a/modules/gui/qt/medialibrary/mlrecentsvideomodel.cpp b/modules/gui/qt/medialibrary/mlrecentsvideomodel.cpp
index 6fd4fc8d74..4b95098c55 100644
--- a/modules/gui/qt/medialibrary/mlrecentsvideomodel.cpp
+++ b/modules/gui/qt/medialibrary/mlrecentsvideomodel.cpp
@@ -29,7 +29,6 @@ enum Role {
VIDEO_PLAYCOUNT,
VIDEO_RESOLUTION,
VIDEO_CHANNEL,
- VIDEO_POSITION,
VIDEO_MRL,
VIDEO_VIDEO_TRACK,
VIDEO_AUDIO_TRACK,
@@ -65,8 +64,6 @@ QVariant MLRecentsVideoModel::data( const QModelIndex& index , int role ) const
return QVariant::fromValue( video->getResolutionName() );
case VIDEO_CHANNEL:
return QVariant::fromValue( video->getChannel() );
- case VIDEO_POSITION:
- return QVariant::fromValue( video->getSavedPosition() );
case VIDEO_MRL:
return QVariant::fromValue( video->getMRL() );
case VIDEO_VIDEO_TRACK:
@@ -89,7 +86,6 @@ QHash<int, QByteArray> MLRecentsVideoModel::roleNames() const
{ VIDEO_PLAYCOUNT, "playcount" },
{ VIDEO_RESOLUTION, "resolution_name" },
{ VIDEO_CHANNEL, "channel" },
- { VIDEO_POSITION, "saved_position" },
{ VIDEO_MRL, "mrl" },
{ VIDEO_AUDIO_TRACK, "audioDesc" },
{ VIDEO_VIDEO_TRACK, "videoDesc" },
diff --git a/modules/gui/qt/medialibrary/mlvideo.cpp b/modules/gui/qt/medialibrary/mlvideo.cpp
index 280420b8db..2d9d385cac 100644
--- a/modules/gui/qt/medialibrary/mlvideo.cpp
+++ b/modules/gui/qt/medialibrary/mlvideo.cpp
@@ -22,15 +22,39 @@
#include <vlc_thumbnailer.h>
+namespace
+{
+QString MsToString( int64_t time )
+{
+ if (time < 0)
+ return "--:--";
+
+ int t_sec = time / 1000;
+ int sec = t_sec % 60;
+ int min = (t_sec / 60) % 60;
+ int hour = t_sec / 3600;
+ if (hour == 0)
+ return QString("%1:%2")
+ .arg(min, 2, 10, QChar('0'))
+ .arg(sec, 2, 10, QChar('0'));
+ else
+ return QString("%1:%2:%3")
+ .arg(hour, 2, 10, QChar('0'))
+ .arg(min, 2, 10, QChar('0'))
+ .arg(sec, 2, 10, QChar('0'));
+
+}
+}
+
MLVideo::MLVideo(vlc_medialibrary_t* ml, const vlc_ml_media_t* data, QObject* parent)
: QObject( parent )
, m_ml( ml )
, m_id( data->i_id, VLC_ML_PARENT_UNKNOWN )
, m_title( QString::fromUtf8( data->psz_title ) )
, m_thumbnail( QString::fromUtf8( data->thumbnails[VLC_ML_THUMBNAIL_SMALL].psz_mrl ) )
+ , m_progress( -1.f )
, m_playCount( data->i_playcount )
, m_thumbnailGenerated( data->thumbnails[VLC_ML_THUMBNAIL_SMALL].b_generated )
- , m_position( 0.f )
, m_ml_event_handle( nullptr, [this](vlc_ml_event_callback_t* cb ) {
assert( m_ml != nullptr );
vlc_ml_event_unregister_callback( m_ml, cb );
@@ -38,19 +62,7 @@ MLVideo::MLVideo(vlc_medialibrary_t* ml, const vlc_ml_media_t* data, QObject* pa
{
assert( data->i_type == VLC_ML_MEDIA_TYPE_VIDEO || data->i_type == VLC_ML_MEDIA_TYPE_UNKNOWN );
- int t_sec = data->i_duration / 1000;
- int sec = t_sec % 60;
- int min = (t_sec / 60) % 60;
- int hour = t_sec / 3600;
- if (hour == 0)
- m_duration = QString("%1:%2")
- .arg(min, 2, 10, QChar('0'))
- .arg(sec, 2, 10, QChar('0'));
- else
- m_duration = QString("%1:%2:%3")
- .arg(hour, 2, 10, QChar('0'))
- .arg(min, 2, 10, QChar('0'))
- .arg(sec, 2, 10, QChar('0'));
+ m_duration = data->i_duration;
for( const vlc_ml_file_t& file: ml_range_iterate<vlc_ml_file_t>( data->p_files ) )
if( file.i_type == VLC_ML_FILE_TYPE_MAIN )
@@ -63,11 +75,8 @@ MLVideo::MLVideo(vlc_medialibrary_t* ml, const vlc_ml_media_t* data, QObject* pa
if ( vlc_ml_media_get_playback_state( ml, data->i_id, VLC_ML_PLAYBACK_STATE_PROGRESS,
&psz_progress ) == VLC_SUCCESS && psz_progress != NULL )
{
- m_progress = atoi( psz_progress );
+ m_progress = atof( psz_progress );
free( psz_progress );
-
- if( data->i_duration )
- m_position = m_progress / (float)data->i_duration;
}
unsigned int numChannel = 0 , maxWidth = 0 , maxHeight = 0;
@@ -169,7 +178,7 @@ QString MLVideo::getThumbnail()
QString MLVideo::getDuration() const
{
- return m_duration;
+ return MsToString( m_duration );
}
QString MLVideo::getMRL() const
@@ -185,7 +194,7 @@ QString MLVideo::getChannel() const
return m_channel;
}
-unsigned int MLVideo::getProgress() const
+float MLVideo::getProgress() const
{
return m_progress;
}
@@ -194,9 +203,9 @@ unsigned int MLVideo::getPlayCount() const
{
return m_playCount;
}
-float MLVideo::getSavedPosition() const
+QString MLVideo::getProgressTime() const
{
- return m_position;
+ return MsToString(m_duration * m_progress);
}
QString MLVideo::getVideoDesc() const
diff --git a/modules/gui/qt/medialibrary/mlvideo.hpp b/modules/gui/qt/medialibrary/mlvideo.hpp
index de4a94dc44..e42546644a 100644
--- a/modules/gui/qt/medialibrary/mlvideo.hpp
+++ b/modules/gui/qt/medialibrary/mlvideo.hpp
@@ -41,11 +41,11 @@ class MLVideo : public QObject
Q_PROPERTY(QString thumbnail READ getThumbnail NOTIFY onThumbnailChanged);
Q_PROPERTY(QString duration READ getDuration CONSTANT);
Q_PROPERTY(QString mrl READ getMRL CONSTANT);
- Q_PROPERTY(unsigned int progress READ getProgress CONSTANT);
+ Q_PROPERTY(float progress READ getProgress CONSTANT);
Q_PROPERTY(unsigned int playCount READ getPlayCount CONSTANT);
Q_PROPERTY(QString resolution_name READ getResolutionName CONSTANT);
Q_PROPERTY(QString channel READ getChannel CONSTANT);
- Q_PROPERTY(float saved_position READ getSavedPosition CONSTANT);
+ Q_PROPERTY(QString progressTime READ getProgressTime CONSTANT);
Q_PROPERTY(QString audioDesc READ getAudioDesc CONSTANT);
Q_PROPERTY(QString videoDesc READ getVideoDesc CONSTANT);
@@ -59,9 +59,9 @@ public:
QString getResolutionName() const;
QString getChannel() const;
QString getMRL() const;
- unsigned int getProgress() const;
+ float getProgress() const;
unsigned int getPlayCount() const;
- float getSavedPosition() const;
+ QString getProgressTime() const;
QString getAudioDesc() const;
QString getVideoDesc() const;
@@ -81,14 +81,14 @@ private:
MLParentId m_id;
QString m_title;
QString m_thumbnail;
- QString m_duration;
+ int64_t m_duration;
QString m_mrl;
QString m_resolution;
QString m_channel;
- unsigned int m_progress;
+ float m_progress;
+ QString m_progressTime;
unsigned int m_playCount;
bool m_thumbnailGenerated;
- float m_position;
QString audioDesc,videoDesc;
std::unique_ptr<vlc_ml_event_callback_t,
diff --git a/modules/gui/qt/medialibrary/mlvideomodel.cpp b/modules/gui/qt/medialibrary/mlvideomodel.cpp
index 0114edca78..365cd4d3cf 100644
--- a/modules/gui/qt/medialibrary/mlvideomodel.cpp
+++ b/modules/gui/qt/medialibrary/mlvideomodel.cpp
@@ -29,7 +29,6 @@ enum Role {
VIDEO_PLAYCOUNT,
VIDEO_RESOLUTION,
VIDEO_CHANNEL,
- VIDEO_POSITION,
VIDEO_MRL,
VIDEO_VIDEO_TRACK,
VIDEO_AUDIO_TRACK,
@@ -74,8 +73,6 @@ QVariant MLVideoModel::data(const QModelIndex& index, int role) const
return QVariant::fromValue( video->getResolutionName() );
case VIDEO_CHANNEL:
return QVariant::fromValue( video->getChannel() );
- case VIDEO_POSITION:
- return QVariant::fromValue( video->getSavedPosition() );
case VIDEO_MRL:
return QVariant::fromValue( video->getMRL() );
case VIDEO_VIDEO_TRACK:
@@ -101,7 +98,6 @@ QHash<int, QByteArray> MLVideoModel::roleNames() const
{ VIDEO_PLAYCOUNT, "playcount" },
{ VIDEO_RESOLUTION, "resolution_name" },
{ VIDEO_CHANNEL, "channel" },
- { VIDEO_POSITION, "saved_position" },
{ VIDEO_MRL, "mrl" },
{ VIDEO_AUDIO_TRACK, "audioDesc" },
{ VIDEO_VIDEO_TRACK, "videoDesc" },
diff --git a/modules/gui/qt/medialibrary/qml/VideoGridItem.qml b/modules/gui/qt/medialibrary/qml/VideoGridItem.qml
index 03f8b105d4..db96508590 100644
--- a/modules/gui/qt/medialibrary/qml/VideoGridItem.qml
+++ b/modules/gui/qt/medialibrary/qml/VideoGridItem.qml
@@ -31,8 +31,7 @@ Widgets.GridItem {
channel: model.channel || ""
isVideo: true
isNew: model.playcount < 1
- showContextButton: true
- progress: model.saved_position > 0 ? model.saved_position : 0
+ progress: model.progress > 0 ? model.progress : 0
pictureWidth: VLCStyle.video_normal_width
pictureHeight: VLCStyle.video_normal_height
onItemDoubleClicked: if ( model.id !== undefined ) { medialib.addAndPlay( model.id ) }
diff --git a/modules/gui/qt/medialibrary/qml/VideoListDisplay.qml b/modules/gui/qt/medialibrary/qml/VideoListDisplay.qml
index 08c4727f15..b09e1d3ea0 100644
--- a/modules/gui/qt/medialibrary/qml/VideoListDisplay.qml
+++ b/modules/gui/qt/medialibrary/qml/VideoListDisplay.qml
@@ -86,7 +86,7 @@ Widgets.KeyNavigableTableView {
color: "limegreen"
}
Widgets.VideoProgressBar {
- value: !rowModel ? 0 : rowModel.saved_position
+ value: !rowModel ? 0 : rowModel.progress
visible: value > 0
anchors {
bottom: parent.bottom
More information about the vlc-commits
mailing list