Warning, /multimedia/kasts/src/kmediasession/example-app/qml/Main.qml is written in an unsupported language. File is not indexed.
0001 /** 0002 * SPDX-FileCopyrightText: 2022-2023 Bart De Vries <bart@mogwai.be> 0003 * 0004 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0005 */ 0006 0007 import QtQuick 0008 import QtQuick.Controls as Controls 0009 import QtQuick.Layouts 0010 import QtMultimedia 0011 import Qt.labs.platform 0012 0013 import org.kde.kirigami as Kirigami 0014 0015 import org.kde.kmediasession 0016 0017 Kirigami.ApplicationWindow { 0018 id: root 0019 0020 title: i18n("Example KMediaSession Player") 0021 0022 KMediaSession { 0023 id: audio 0024 playerName: "Kasts" 0025 desktopEntryName: "org.kde.kasts" 0026 0027 onRaiseWindowRequested: { 0028 root.visible = true; 0029 root.show(); 0030 root.raise(); 0031 root.requestActivate(); 0032 } 0033 onQuitRequested: { 0034 root.close(); 0035 } 0036 onNextRequested: { 0037 console.log("next"); 0038 } 0039 onPreviousRequested: { 0040 console.log("previous"); 0041 } 0042 } 0043 0044 ColumnLayout { 0045 RowLayout { 0046 Controls.ComboBox { 0047 textRole: "text" 0048 valueRole: "value" 0049 model: ListModel { 0050 id: backendModel 0051 } 0052 Component.onCompleted: { 0053 // have to use Number because QML doesn't know about enum names 0054 for (var index in audio.availableBackends) { 0055 backendModel.append({"text": audio.backendName(audio.availableBackends[index]), 0056 "value": Number(audio.availableBackends[index])}); 0057 0058 if (Number(audio.availableBackends[index]) === audio.currentBackend) { 0059 currentIndex = index; 0060 } 0061 } 0062 } 0063 0064 onActivated: { 0065 audio.currentBackend = currentValue; 0066 } 0067 } 0068 } 0069 RowLayout { 0070 Controls.Button { 0071 icon.name: "document-open-folder" 0072 text: i18n("Select Fileā¦") 0073 onClicked: filePathDialog.open() 0074 } 0075 0076 FileDialog { 0077 id: filePathDialog 0078 title: i18n("Select Media File") 0079 currentFile: audio.source 0080 onAccepted: { 0081 audio.source = filePathDialog.file; 0082 } 0083 } 0084 Controls.Label { 0085 text: i18n("OR") 0086 } 0087 Controls.TextField { 0088 id: urlField 0089 Layout.fillWidth: true 0090 text: audio.source 0091 } 0092 Controls.Button { 0093 text: i18n("Open") 0094 onClicked: { 0095 audio.source = urlField.text; 0096 } 0097 } 0098 } 0099 RowLayout { 0100 Controls.Button { 0101 text: i18n("Play") 0102 enabled: audio.canPlay 0103 icon.name: "media-playback-start" 0104 onClicked: { 0105 audio.play() 0106 } 0107 } 0108 Controls.Button { 0109 text: i18n("Pause") 0110 enabled: audio.canPause 0111 icon.name: "media-playback-pause" 0112 onClicked: { 0113 audio.pause() 0114 } 0115 } 0116 Controls.Button { 0117 text: i18n("Stop") 0118 icon.name: "media-playback-stop" 0119 onClicked: { 0120 audio.stop() 0121 } 0122 } 0123 } 0124 RowLayout { 0125 Controls.Label { 0126 text: audio.position / 1000 0127 Layout.preferredWidth: 50 0128 horizontalAlignment: Text.AlignRight 0129 } 0130 Controls.Slider { 0131 Layout.fillWidth: true 0132 Layout.margins: 0 0133 padding: 0 0134 from: 0 0135 to: audio.duration 0136 value: audio.position 0137 onMoved: audio.position = value; 0138 enabled: audio.playbackState !== KMediaSession.StoppedState 0139 } 0140 Controls.Label { 0141 text: audio.duration / 1000 0142 Layout.preferredWidth: 50 0143 } 0144 } 0145 RowLayout { 0146 Controls.CheckBox { 0147 text: i18n("Mute") 0148 enabled: audio.playbackState !== KMediaSession.StoppedState 0149 checked: audio.muted 0150 onToggled: audio.muted = checked 0151 } 0152 Controls.Slider { 0153 Layout.fillWidth: true 0154 Layout.margins: 0 0155 padding: 0 0156 enabled: audio.playbackState !== KMediaSession.StoppedState 0157 from: 0 0158 to: 100 0159 value: audio.volume 0160 onMoved: audio.volume = value; 0161 } 0162 Controls.ComboBox { 0163 textRole: "text" 0164 valueRole: "value" 0165 model: [{text: "0.5x", value: 0.5}, 0166 {text: "1x", value: 1.0}, 0167 {text: "1.5x", value: 1.5}] 0168 Component.onCompleted: currentIndex = indexOfValue(audio.playbackRate) 0169 onActivated: audio.playbackRate = currentValue 0170 } 0171 } 0172 ColumnLayout { 0173 Controls.Label { 0174 text: i18n("Title: %1", audio.metaData.title) 0175 } 0176 Controls.Label { 0177 text: i18n("Artist: %1", audio.metaData.artist) 0178 } 0179 Controls.Label { 0180 text: i18n("Album: %1", audio.metaData.album) 0181 } 0182 Image { 0183 fillMode: Image.PreserveAspectFit 0184 Layout.preferredHeight: 200 0185 Layout.preferredWidth: 200 0186 source: audio.metaData.artworkUrl 0187 } 0188 } 0189 ColumnLayout { 0190 Controls.Label { 0191 text: i18n("Media status: %1", audio.mediaStatus) 0192 } 0193 Controls.Label { 0194 text: i18n("Playback status: %1", audio.playbackState) 0195 } 0196 Controls.Label { 0197 text: i18n("Error: %1", audio.error) 0198 } 0199 } 0200 } 0201 } 0202