Saturday 30 August 2014

SirenSong Music Player for SailfishOS

I've been working on a Music Player App for SailfishOS largely due to the fact that there isn't a lot to choose from currently and there seems to be a reasonable demand for a good Music Player aside from the stock one from Jolla.

Currently this Music Player is fairly basic and no configuration options, but it provides simple but effective library navigation and playback features.

SirenSong v0.2

https://github.com/r0kk3rz/SirenSong-Media-Player

https://openrepos.net/content/r0kk3rz/siren-song-music-player




Features

  • People Style List Menu for large library support
  • Random Infinitely Queuing Playlist
  • Next/Play/Pause Cover Actions 
  • Headset Buttons Functionality

To Be Implemented 

  • Album/Artist/Genre Sorting Options
  • Search Functionality
  • Playlist Management
  • Equalizer
  • DBus Interface
  • Headphone Jack Events Detection
  • App Drawer Icon
  • Lots...

Known Issues

  • Maybe memory issues if left running for a long time

Monday 11 August 2014

Qt5Sparql and Tracker

Tracker is a service that runs in the background and collects information about things that are on the phone and stores it all into a Sparql database. On the Jolla, Tracker is used for things like the Gallery App and the Media App, so if you wanted to create a gallery or a music player app half the work is already done for you.

You can query the Tracker database from the command line using the tracker-sparql command
eg. tracker-sparql -q "SELECT
?title ?artist ?length ?album
WHERE { ?song a nmm:MusicPiece .
    ?song nie:title ?title .
    ?song nfo:duration ?length .
        ?song nie:url ?url .
    ?song nmm:performer ?aName .
    ?aName nmm:artistName ?artist .
    ?song nmm:musicAlbum ?malbum .
    ?malbum nmm:albumTitle ?album
    FILTER regex(?title, '^A', 'i')
}"


This is a select query that will return info about the music files indexed by tracker, notice the FILTER line is a regex that will only return items that start with 'A'.

Another cool type of query is the ASK query, which will return true or false depending on whether any results exist
eg. tracker-sparql -q "ASK {
    ?song a nmm:MusicPiece .
    ?song nie:title ?title
    FILTER regex(?title, '^A', 'i') 
}"


Sound great! But how do you use it?

First thing is you need to install the Qt5Sparql libraries into your development environment

You can do this by opening your project in QtCreator and
  1. Click on SailfishOS on the side menu
  2. Under Targets click Manage Target on your desired environment
  3. In the search area, type in sparql
  4. Install all shown packages
Once you've done that you need to add QtSparql to the CONFIG area in your .pro file

In your QML file you can now write import QtSparql 1.0, but it will still have a red line underneath it with a "QML Module does not contain information about components contained in plugins" error. This error can be ignored and will still compile and run, but the QtCreator IDE will not autocomplete for you. If you want to fix the error then you need to use a qmlplugdump program to generate the required file, but it doesn't come with the SailfishOS SDK and I couldn't be bothered trying to compile it myself from source.

Instead you can use the git repository as documentation on the objects and what signals/properties/methods they have

https://github.com/nemomobile/libqtsparql/tree/master/src/sparql

Also in there is a bunch of examples which are fairly handy

https://github.com/nemomobile/libqtsparql/tree/master/examples/sparql

Example Code

The easiest way to get going is with something like the following, its a ListModel QML object that gets its ListItems from Tracker using a SPARQL query

SparqlListModel {
   id: queryModel
   objectName: queryModel
 
   // create a new SparqlConnection for the queryModel
   connection: SparqlConnection { id:sparqlConnection;  
                                  objectName:"sparqlConnection";  
                                  driver:"QTRACKER_DIRECT" }

   // This is the query for the model

   query: "SELECT ?title ?artist ?length ?album ?url "+
      "WHERE { ?song a nmm:MusicPiece . "+
      "?song nie:title ?title . "+
      "?song nfo:duration ?length . "+
      "?song nie:url ?url ." +
      "?song nmm:performer ?aName . "+
      "?aName nmm:artistName ?artist . "+
      "?song nmm:musicAlbum ?malbum . "+
      "?malbum nmm:albumTitle ?album "+
      "} "
}