Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How to access Metadata from audio files
Forum Updated to NodeBB v4.3 + New Features

How to access Metadata from audio files

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
20 Posts 2 Posters 6.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Nisha_R
    28 Dec 2016, 10:29

    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 file

     ApplicationWindow{
        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.

    P Offline
    P Offline
    p3c0
    Moderators
    wrote on 29 Dec 2016, 11:43 last edited by
    #2

    @Nisha_R First make sure your audio contains the requried metadata.
    Also instead of Component.onCompleted try using onStatusChanged signal handler and check for Loaded status after which try extracting the metadata.

    157

    1 Reply Last reply
    0
    • N Offline
      N Offline
      Nisha_R
      wrote on 30 Dec 2016, 06:39 last edited by
      #3

      @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}
      
      
      1 Reply Last reply
      0
      • P Offline
        P Offline
        p3c0
        Moderators
        wrote on 30 Dec 2016, 06:43 last edited by
        #4

        @Nisha_R

        console.log(a.title)

        Shouldn't that be a.metaData.title ?

        157

        1 Reply Last reply
        1
        • N Offline
          N Offline
          Nisha_R
          wrote on 2 Jan 2017, 05:30 last edited by
          #5

          Thank you @p3c0
          still the output remains undefined!!

          1 Reply Last reply
          1
          • P Offline
            P Offline
            p3c0
            Moderators
            wrote on 2 Jan 2017, 05:41 last edited by
            #6

            @Nisha_R Are you sure the media file contains metadata ?
            I just tried this example and in onPressed, console.log(playMusic.metaData.title) printed the title as expected.

            157

            1 Reply Last reply
            1
            • N Offline
              N Offline
              Nisha_R
              wrote on 2 Jan 2017, 05:43 last edited by
              #7

              @p3c0 i am sure the song contains the metadata because i have edited it online.
              could you please share the code you have worked on?

              1 Reply Last reply
              1
              • P Offline
                P Offline
                p3c0
                Moderators
                wrote on 2 Jan 2017, 05:47 last edited by
                #8

                @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)
                             }
                         }
                     }
                }
                
                

                157

                1 Reply Last reply
                0
                • N Offline
                  N Offline
                  Nisha_R
                  wrote on 2 Jan 2017, 08:42 last edited by
                  #9

                  @p3c0 thank you.

                  1 Reply Last reply
                  1
                  • N Offline
                    N Offline
                    Nisha_R
                    wrote on 2 Jan 2017, 09:14 last edited by
                    #10

                    @p3c0 Thank you again,
                    i have got it right when i set the relative path for the mp3 file i,e the source , but when i try to access the mp3 files from resources it is still undefined.

                    1 Reply Last reply
                    1
                    • P Offline
                      P Offline
                      p3c0
                      Moderators
                      wrote on 2 Jan 2017, 09:26 last edited by
                      #11

                      @Nisha_R How did you set the source ?

                      157

                      1 Reply Last reply
                      1
                      • N Offline
                        N Offline
                        Nisha_R
                        wrote on 3 Jan 2017, 05:02 last edited by Nisha_R 1 Mar 2017, 05:03
                        #12

                        @p3c0 ,
                        i had initially dumped the mp3 files in resources folder and tried to access those in my code.

                        1 Reply Last reply
                        0
                        • P Offline
                          P Offline
                          p3c0
                          Moderators
                          wrote on 3 Jan 2017, 05:06 last edited by
                          #13

                          @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.

                          157

                          1 Reply Last reply
                          0
                          • N Offline
                            N Offline
                            Nisha_R
                            wrote on 3 Jan 2017, 06:45 last edited by Nisha_R 1 Mar 2017, 06:54
                            #14

                            @p3c0 this is what i have given.
                            Audio {
                            id: playMusic
                            source: "qrc:/music/2.mp3;"
                            }
                            music being the folder in resources.

                            1 Reply Last reply
                            0
                            • P Offline
                              P Offline
                              p3c0
                              Moderators
                              wrote on 3 Jan 2017, 07:14 last edited by
                              #15

                              @Nisha_R Why the extra semicolon at the end in source ?
                              Does the Application Output show any errors ?

                              157

                              1 Reply Last reply
                              0
                              • N Offline
                                N Offline
                                Nisha_R
                                wrote on 3 Jan 2017, 07:23 last edited by
                                #16

                                @p3c0 there is no error with respect to the semicolon .
                                setting its path with respect to resources shows undefined, but when its relative path is set the metadata is displayed.

                                1 Reply Last reply
                                1
                                • P Offline
                                  P Offline
                                  p3c0
                                  Moderators
                                  wrote on 3 Jan 2017, 07:26 last edited by
                                  #17

                                  @Nisha_R Did you try removing the semicolon ?
                                  Also are you sure the file is present at the same location in the resource ?

                                  157

                                  1 Reply Last reply
                                  1
                                  • N Offline
                                    N Offline
                                    Nisha_R
                                    wrote on 3 Jan 2017, 09:46 last edited by
                                    #18

                                    @p3c0
                                    yes , i have tried, still undefined.

                                    1 Reply Last reply
                                    0
                                    • P Offline
                                      P Offline
                                      p3c0
                                      Moderators
                                      wrote on 3 Jan 2017, 10:10 last edited by
                                      #19

                                      @Nisha_R Does it play from resources ? Can you post a complete minimal example with this Audio element here?

                                      157

                                      1 Reply Last reply
                                      0
                                      • N Offline
                                        N Offline
                                        Nisha_R
                                        wrote on 3 Jan 2017, 10:18 last edited by Nisha_R 1 Mar 2017, 12:00
                                        #20

                                        @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();
                                                                     }
                                                                              }
                                                            }
                                           }
                                        
                                        1 Reply Last reply
                                        1

                                        11/20

                                        2 Jan 2017, 09:26

                                        • Login

                                        • Login or register to search.
                                        11 out of 20
                                        • First post
                                          11/20
                                          Last post
                                        0
                                        • Categories
                                        • Recent
                                        • Tags
                                        • Popular
                                        • Users
                                        • Groups
                                        • Search
                                        • Get Qt Extensions
                                        • Unsolved