DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Making a Very Small MP3 Player With QML

How you create your own music player with just a few lines of code

Paul Hammant user avatar by
Paul Hammant
·
Sep. 07, 15 · Tutorial
Like (1)
Save
Tweet
Share
3.01K Views

Join the DZone community and get the full member experience.

Join For Free

i’ve been futzing around with qml. here’s a tiny mp3 player, for a single song in the current directory.

it would be nice if the mac’s homebrew could install qml for you, but it can’t (yet i guess). thus, i had to install the qt 5.5 piece manually ( via it’s installer at qt.io).

the installer doesn’t make links for commands into /usr/local/bin or similar, so forgive the long path in the shebang line below (line 1):

#!/usr/bin/env /users/paul/qt/5.5/clang_64/bin/qml.app/contents/macos/qml

import qtquick 2.2
import qtmultimedia 5.0

rectangle {
    width: 200
    height: 100
    property bool playing: false

    text {
        anchors.centerin: parent
        // one way binding - neat!
        text: playing ? "stop music" : "start music"
    }
    audio {
        id: playmusic
        source: "memphisslim-ijustlandedinyourtown.mp3"
    }    
    mousearea {
        anchors.fill: parent
        onclicked: {
            if(playing == true) {
                playmusic.stop()
                playing = false
            } else {
                playmusic.play()
                playing = true
            }
        }
    }
}

that’s an elegant syntax imo. not ugly bedfellows, like html and javascript.

the app only plays one song though. if you’re interested, that song is memphis slim’s “i just landed in your town”. read about it on publicdomain4u , or grab the song from archive.org

the app on mac os x:

i’d like the app to offer a selection of a choice of songs from the current directory. there’s a repeat{ } structure in qml that looks exactly what i want, but no ability to list files, which is a gaping hole in the api. at least, if there is, i can’t find it, as google search results are littered with previous versions of qt, and indeed the name for qml isn’t standardized (it is alternately known as qtquick and qtcreator). i believe the owners of qt want you to dive off to c++ or a high level language that can bootstrap qml to do heavy lifting like list_the_files_or_subdirectories_in_a_directory . qml in the style that i have it, leverages javascript for the programmatic bits (as opposed to declarative).

the nodejs people had to enhance javascript to add a lot more functions to make it usable server-side. for my needs that would be the file system api. lo and behold, a oleg shparber (trollixx) has done just that with a port of node.js to qml . that is linux only though, and only after patching your own build of qt 5.5 (for now).



MP3

Published at DZone with permission of Paul Hammant, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • How To Generate Code Coverage Report Using JaCoCo-Maven Plugin
  • Kotlin Is More Fun Than Java And This Is a Big Deal
  • How Observability Is Redefining Developer Roles
  • A Complete Guide to AngularJS Testing

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: