PDA

View Full Version : HowTo read playlist pls file



KeineAhnung
17th August 2014, 18:57
Hi there,

I would like to read a playlist .pls file to tell Audio what music to play but I cannot get QFile to read it. My application shall be an Sailfish app.
To read a file I followed this (http://developer.nokia.com/community/wiki/Reading_and_writing_files_in_QML) tutorial.
If I use this code with source: "qrc:/playlist.pls" (currently I provide the playlist within my resource file)

FileIO {
id: myFile
source: "my_file.txt"
onError: console.log(msg)
}
I get this error:

[W] unknown:39 - file:///usr/share/Test/qml/Test.qml:39:30: Type FirstPage unavailable
initialPage: Component { FirstPage { } }
^
[W] unknown:57 - file:///usr/share/Test/qml/pages/FirstPage.qml:57:21: Invalid property assignment: "source" is a read-only property
source: "qrc:/playlist.pls"
I do not understand that because I only want to open the file as read-only, so why is the string invalid?

Then I commented the source out and put the path directly into the cpp file.

...
mSource = "qrc:/playlist.pls";
if (mSource.isEmpty()){
...
Then the file could be opened but not read and I get the error message:

[D] onError:58 - Unable to open the file
[D] onCompleted:125 -
I spend nearly to days now to figure out what is wrong but I just cannot find anything on the web. Can someone help me please?

ChrisW67
17th August 2014, 21:02
As the error message says, "source" is a read-only property of the FileIO object. Fix the declaration of your FileIO class to allow writing the source property and you will be able to write to it. This has nothing to do with writing to the file itself (which you cannot do).

Here is a full example:
http://developer.nokia.com/community/wiki/Reading_and_writing_files_in_QML

KeineAhnung
19th August 2014, 09:37
Hi Chris,

I was working with that example. But even after copying that example 1 to 1 I still get the error that the file cannot be opened. On my Mac I can open the file with TextEdit, so I do not think that it is corrupted. Any idea what I can do to find the error?

Thanks!

ChrisW67
19th August 2014, 12:51
The first error message has nothing to do with being able to write to the file. It is complaining about not being able to write to the "source" property of the object.

As for the other error message,


Then the file could be opened but not read and I get the error message: ...

This error message is output by the example's read() if the file cannot be opened. Chances are the path is wrong, or the resource file has not been built into your project.

KeineAhnung
19th August 2014, 20:45
I have been using the file with other functions and there the it worked. So I am quite sure that my path is correct. Never the less I changed my approach and try to load the playlist directly using QMediaPlaylist.