|
得到所有音频项目并创建一个播放列表。
- var audio = document.getElementById("audio");
- // Retrieve the ContentManager interface instance using the tizen global object
- var manager = tizen.content;
- // Retrieving the Audio list.
- var contentType = "AUDIO";
- var filter = new tizen.AttributeFilter("type", "EXACTLY", contentType);
- manager.find(mediaItemArray, onError, null, filter);
- function onError(response) {
- console.log( "The following error occurred: " + response.name);
- }
- var onclickFunction = function() {
- alert("clicked" + this.innerHTML);
- audio.src = this.contentURL;
- };
- function mediaItemArray (contents) {
- var itemsList = document.getElementById('playlist');
- console.log("Successfully retrieved the list of Audio items");
- for (var i=0; i < contents.length; i++) {
- console.log(i + ":" + contents[i].type + ":" + contents[i].title + ":" +contents[i].mimeType);
- console.log("album:" + contents[i].album);
- console.log("artists:" + contents[i].artists[0]);
- console.log("duration:" + contents[i].duration);
- console.log("Item bitrate: " + contents[i].bitrate);
- console.log("Item trackNumber: " + contents[i].trackNumber);
- console.log("Item size: " + contents[i].size);
- var listItem = document.createElement("li");
- listItem.innerHTML = contents[i].title;
- listItem.contentURL = contents[i].contentURI;
- listItem.onclick = onclickFunction;
- itemsList.appendChild(listItem);
- }
- }
- // Requires the following Tizen Privilege:
- // <tizen:privilege name="http://tizen.org/privilege/content.read"/>
- // Add this line to config.xml file
复制代码 |
|