harbour-fernschreiber/qml/components/messageContent/MessageAudio.qml

97 lines
3.7 KiB
QML
Raw Permalink Normal View History

2020-08-28 15:14:05 +03:00
/*
Copyright (C) 2020 Sebastian J. Wolf and other contributors
2020-08-28 15:14:05 +03:00
This file is part of Fernschreiber.
Fernschreiber is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Fernschreiber is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fernschreiber. If not, see <http://www.gnu.org/licenses/>.
*/
2020-10-31 22:49:03 +03:00
import QtQuick 2.6
2020-08-28 15:14:05 +03:00
import Sailfish.Silica 1.0
2020-10-31 22:50:32 +03:00
import QtMultimedia 5.6
import "../"
import "../../js/twemoji.js" as Emoji
import "../../js/functions.js" as Functions
import "../../js/debug.js" as Debug
2020-11-20 23:58:26 +03:00
2020-08-28 15:14:05 +03:00
MessageContentFileInfoBase {
id: contentItem
fileInformation: rawMessage.content.audio.audio
thumbnail: rawMessage.content.audio.album_cover_thumbnail
minithumbnail: rawMessage.content.audio.album_cover_minithumbnail
primaryText: Emoji.emojify(rawMessage.content.audio.performer, primaryLabel.font.pixelSize)
secondaryText: Emoji.emojify(rawMessage.content.audio.title, secondaryLabel.font.pixelSize)
tertiaryLabel.visible: (duration || (audioPlayer.duration/1000)) > 0
tertiaryText: (audioPlayer.position > 0 || audioPlayer.playbackState === Audio.PlayingState ? (Format.formatDuration(audioPlayer.position/1000, Formatter.DurationShort)+" / ") : "") + Format.formatDuration(contentItem.duration > 0 ? contentItem.duration : (audioPlayer.duration/1000), Formatter.DurationShort)
leftButton {
icon.source: audioPlayer.playbackState === Audio.PlayingState || (file.isDownloadingActive && audioPlayer.autoPlay) ? "image://theme/icon-m-pause": "image://theme/icon-m-play"
onClicked: {
if(!file.isDownloadingCompleted && !file.isDownloadingActive) {
file.load();
audioPlayer.autoPlay = true;
} else if(file.isDownloadingActive) {
audioPlayer.autoPlay = false;
file.cancel();
} else if(file.isDownloadingCompleted) {
//playPause
if(audioPlayer.playbackState === Audio.PlayingState) {
audioPlayer.pause();
2020-08-28 15:14:05 +03:00
} else {
audioPlayer.play();
2020-08-28 15:14:05 +03:00
}
}
}
}
property int duration: rawMessage.content.audio.duration
2020-08-28 15:14:05 +03:00
Audio {
id: audioPlayer
source: file.isDownloadingCompleted ? file.path : ""
autoPlay: false
2020-08-28 15:14:05 +03:00
}
Slider {
2020-08-28 15:14:05 +03:00
width: parent.width
anchors {
left: parent.left
leftMargin: -Screen.width/16
right: parent.right
rightMargin: -Screen.width/16
top: primaryItem.bottom
topMargin: -height/3
}
minimumValue: 0
maximumValue: audioPlayer.duration ? audioPlayer.duration : 0.1
stepSize: 1
value: audioPlayer.position
enabled: audioPlayer.seekable
visible: file.isDownloadingCompleted && audioPlayer.playbackState === Audio.PlayingState || audioPlayer.playbackState === Audio.PausedState
opacity: visible ? 1.0 : 0.0
Behavior on opacity { FadeAnimation {} }
height: visible ? implicitHeight : 0
Behavior on height { NumberAnimation { duration: 200 } }
highlighted: contentItem.highlighted || down
onReleased: {
audioPlayer.seek(Math.floor(value));
audioPlayer.play();
2020-08-28 15:14:05 +03:00
}
}
}