How to access Metadata from audio files
-
wrote on 28 Dec 2016, 10:29 last edited by p3c0
hello ,
i am working on the simulation of Music Player in QT using QML,
here is my code to access the metadata from the mp3 fileApplicationWindow{ visible: true width: 640 height: 480 Audio { id:audio1 source:"/music/2.mp3" } Component.onCompleted :{ console.log(audio1.metaData.title) } }
but the output is undefined for metaData.title.
-
hello ,
i am working on the simulation of Music Player in QT using QML,
here is my code to access the metadata from the mp3 fileApplicationWindow{ visible: true width: 640 height: 480 Audio { id:audio1 source:"/music/2.mp3" } Component.onCompleted :{ console.log(audio1.metaData.title) } }
but the output is undefined for metaData.title.
@Nisha_R First make sure your audio contains the requried metadata.
Also instead ofComponent.onCompleted
try using onStatusChanged signal handler and check forLoaded
status after which try extracting the metadata. -
wrote on 30 Dec 2016, 06:39 last edited by
@p3c0 Thank you ,
i have tried with the below code, could you suggest if there are any changes to be made.Window { visible: true width: 640 height: 480 title: qsTr("Hello World") MouseArea { anchors.fill: parent onClicked: { a.play() console.log(a.title) } } MediaPlayer{ id:a source: musicfile path readonly property string title: !!metaData.author && !!metaData.year ? qsTr("%1 - %2").arg(metaData.author).arg(metaData.year): metaData.author && metaData.year && source}
-
-
-
@Nisha_R Thats strange. Try following:
import QtQuick 2.6 import QtMultimedia 5.6 Item { width: 400 height: 400 Text { text: "Click Me!"; font.pointSize: 24; width: 150; height: 50; MediaPlayer { id: playMusic source: "MySong.mp3" } MouseArea { id: playArea anchors.fill: parent onPressed: { playMusic.play() console.log(playMusic.metaData.title) console.log(playMusic.metaData.albumTitle) console.log(playMusic.metaData.genre) console.log(playMusic.metaData.year) } } } }
-
@Nisha_R How did you set the source ?
-
@Nisha_R No. I meant to say the source url. What does it look like? Can you post it ? Checking if the url from resource is correct.
-
@Nisha_R Why the extra semicolon at the end in
source
?
Does the Application Output show any errors ? -
@Nisha_R Did you try removing the semicolon ?
Also are you sure the file is present at the same location in the resource ? -
@Nisha_R Does it play from resources ? Can you post a complete minimal example with this
Audio
element here? -
wrote on 3 Jan 2017, 10:18 last edited by Nisha_R 1 Mar 2017, 12:00
@p3c0 okay that will be helpful.
MediaPlayer{ id: player; playlist: Playlist { id: playlist PlaylistItem { source: "qrc:/music/4.mp3"} PlaylistItem { source: "qrc:/music/5.mp3"} } } ListView { model: playlist; delegate: Text { font.pixelSize: 16; text: player.metaData.title+"\n"+player.metaData.albumArtist+"\n"+player.metaData.author; } } Rectangle { id: rectangle2 x: 182 y: 224 width: 78 height: 51 color: "#b35e5e" MouseArea { anchors.fill: parent; onPressed: { if (player.playbackState != Audio.PlayingState) { player.play() } else { player.pause(); } } } }
5/20