Files
qyouradio/Player.qml
Dark Steveneq d46d37c465
Some checks failed
Build / build-linux (push) Failing after 17s
Build / build-windows (push) Has been cancelled
Refactor Player, fix playing indicator
2025-10-14 13:36:21 +02:00

67 lines
1.5 KiB
QML

import QtQuick 6.8
import QtMultimedia 6.8
pragma Singleton
MediaPlayer {
readonly property var streams: ([
{
name: "Autoradio",
streamURL: "https://youradio.nonamesoft.xyz/api/autoradio"
},
{
name: "Live Mix",
streamURL: "https://youradio.nonamesoft.xyz/api/live"
},
{
name: "Deep Bass",
streamURL: "https://youradio.nonamesoft.xyz/api/bassboosted"
}
])
id: player
source: ""
audioOutput: AudioOutput {
id: output
volume: 0.4
}
onErrorOccurred: function(error, errorString) {
const index = currentIndex
currentIndex = null
currentIndex = index;
}
property alias volume: output.volume
readonly property var loading: mediaStatus == Qt.LoadingMedia
property var currentIndex: null
property var currentStream: null
function startPlaying(index) {
if ((playing && index == currentIndex) || index < 0 || index >= streams.length) {
return;
}
if (playing) {
player.stop();
}
print("Starting playing stream no. " + index);
currentIndex = index;
currentStream = streams[index];
source = currentStream.streamURL;
player.play();
}
function stopPlaying() {
if (!playing) {
return;
}
print("Stopping playback");
currentIndex = null;
currentStream = null;
source = "";
player.stop()
}
}