diff --git a/Main.qml b/Main.qml index 646cc8e..cdeeca5 100755 --- a/Main.qml +++ b/Main.qml @@ -19,20 +19,45 @@ ApplicationWindow { Layout.fillWidth: true Label { - text: "QYR" + text: "QYouRadio" heading: "h3" font.bold: true } - Item { - Layout.fillWidth: true - } + // Item { + // Layout.fillWidth: true + // } - Label { - visible: Player.playing - text: "Playback active" - heading: "h4" - font.bold: true + Rectangle { + Layout.leftMargin: 20 + visible: Player.currentIndex != null + color: Colors.primary + radius: 5 + clip: true + width: 320 + height: 36 + + Label { + anchors.top: parent.top + anchors.left: parent.left + anchors.right: parent.right + anchors.topMargin: 1 + anchors.leftMargin: 4 + anchors.rightMargin: 4 + text: (Player.loading ? "Loading " : "Playing ") + (Player.currentIndex != null ? qsTr(Player.currentStream.name) : "") + heading: "h2" + } + + Label { + anchors.bottom: parent.bottom + anchors.left: parent.left + anchors.right: parent.right + anchors.bottomMargin: 1 + anchors.leftMargin: 4 + anchors.rightMargin: 4 + text: "Title will go here" + heading: "h4" + } } Item { @@ -79,8 +104,7 @@ ApplicationWindow { asynchronous: true visible: status == Loader.Ready sourceComponent: ViewPlayer { - title: qsTr("Autoradio") - streamURL: "https://youradio.nonamesoft.xyz/api/autoradio" + index: 0 } } Loader { @@ -88,8 +112,7 @@ ApplicationWindow { asynchronous: true visible: status == Loader.Ready sourceComponent: ViewPlayer { - title: qsTr("Live Mix") - streamURL: "https://youradio.nonamesoft.xyz/api/live" + index: 1 } } Loader { @@ -97,8 +120,7 @@ ApplicationWindow { asynchronous: true visible: status == Loader.Ready sourceComponent: ViewPlayer { - title: qsTr("Deep Bass") - streamURL: "https://youradio.nonamesoft.xyz/api/bassboosted" + index: 2 } } } diff --git a/Player.qml b/Player.qml index 535947f..63f5628 100644 --- a/Player.qml +++ b/Player.qml @@ -1,33 +1,66 @@ +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 } - - property alias volume: output.volume - function startPlaying(url) { - if (playing) { + 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; } - console.log("Starting playback from " + url); - source = url; - play(); + if (playing) { + player.stop(); + } + print("Starting playing stream no. " + index); + currentIndex = index; + currentStream = streams[index]; + source = currentStream.streamURL; + player.play(); } function stopPlaying() { - console.log("Stopping playback..."); + if (!playing) { + return; + } + print("Stopping playback"); + currentIndex = null; + currentStream = null; source = ""; - stop(); - } - - onErrorOccurred: function(error, errorString) { - stopPlaying(); + player.stop() } } diff --git a/QYRComponents/Slider.qml b/QYRComponents/Slider.qml index 1222d7f..a851135 100644 --- a/QYRComponents/Slider.qml +++ b/QYRComponents/Slider.qml @@ -8,20 +8,20 @@ Slider { implicitWidth: 130 implicitHeight: 20 - OpacityAnimator on opacity{ - from: 0.7 - to: 1 - duration: 200 - target: this - running: parent.hovered - } - OpacityAnimator on opacity{ - from: 1 - to: 0.7 - duration: 200 - target: this - running: !parent.hovered - } + // OpacityAnimator on opacity{ + // from: 0.7 + // to: 1 + // duration: 200 + // target: parent + // running: parent.hovered + // } + // OpacityAnimator on opacity{ + // from: 1 + // to: 0.7 + // duration: 200 + // target: parent + // running: !parent.hovered + // } background: Rectangle { color: "#555" diff --git a/ViewPlayer.qml b/ViewPlayer.qml index c166c8a..217b2f5 100644 --- a/ViewPlayer.qml +++ b/ViewPlayer.qml @@ -8,14 +8,12 @@ ColumnLayout { Layout.alignment: Qt.AlignVCenter Layout.fillWidth: true - property string title: "" - property string streamURL: "" - property string metaURL: "" + property var index: null Label { Layout.fillWidth: true Layout.bottomMargin: 20 - text: title + text: index != null ? Player.streams[index].name : "Invalid station" heading: "h2" horizontalAlignment: Text.AlignHCenter } @@ -27,27 +25,6 @@ ColumnLayout { horizontalAlignment: Text.AlignHCenter } - Label { - Layout.fillWidth: true - text: "Artist: " - heading: "h3" - horizontalAlignment: Text.AlignHCenter - } - - Label { - Layout.fillWidth: true - text: "Genre: " - heading: "h3" - horizontalAlignment: Text.AlignHCenter - } - - Label { - Layout.fillWidth: true - text: "Bitrate: " + " kbps" - heading: "h3" - horizontalAlignment: Text.AlignHCenter - } - Label { Layout.fillWidth: true text: "Listeners: " @@ -55,9 +32,15 @@ ColumnLayout { horizontalAlignment: Text.AlignHCenter } + Label { + Layout.topMargin: 20 + text: (Player.currentIndex != null && Player.currentIndex != parent.index) ? qsTr("Another station is currently playing") : "" + heading: "h2" + horizontalAlignment: Text.AlignHCenter + } + RowLayout { Layout.fillWidth: false - Layout.topMargin: 20 Layout.alignment: Qt.AlignHCenter width: 220 @@ -69,7 +52,7 @@ ColumnLayout { if (Player.playing) { Player.stopPlaying(); } else { - Player.startPlaying(parent.parent.streamURL); + Player.startPlaying(parent.parent.index); } } }