<script type="text/javascript">
mui.init();
document.addEventListener("plusready", function() {
if(plus.os.name == "Android") {
var Context = plus.android.importClass("android.content.Context");
var Cursor = plus.android.importClass("android.database.Cursor");
var MediaStore = plus.android.importClass("android.provider.MediaStore");
var list = document.getElementById("list");
var li;
var resolver = Context.getContentResolver();
var c =resolver.query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, null, null, null, null);
c.moveToFirst();
if(c != null) {
while(c.moveToNext()) {
//扫描本地文件,得到歌曲的相关信息
var music_name = c.getString(c.getColumnIndex(MediaStore.Audio.Media.TITLE));
var music_singer = c.getString(c.getColumnIndex(MediaStore.Audio.Media.ARTIST));
var music_time = c.getString(c.getColumnIndex(MediaStore.Audio.Media.DURATION));
var music_path = c.getString(c.getColumnIndex(MediaStore.Audio.Media.DATA));
li = document.createElement('li');
li.className = "mui-table-view-cell mui-media";
li.setAttribute('name', music_name);
li.setAttribute('data-type', 'File');
li.innerHTML = '<a class="mui-navigate-right">' +
'<img class="mui-media-object mui-pull-left" src="img/folder.png">' +
'<div class="mui-media-body">' + music_name +
'<p class="mui-ellipsis">' + music_singer +
'</p></div></a>';
list.appendChild(li);
}
}
}
}, false);
</script>
但是一直出现Uncaught TypeError: Object function (create) { this.UUID = window.plus.tools.UUID('JSB'); this.TYPE = 'JSBObject'; var args = window.plus.ios.__Tool.process(arguments); if ( create && plus.tools.I...<omitted>...r' at pages/my/LocalMusic.html:110 的错误。就是这行var resolver = Context.getContentResolver();
不知道怎么解决。
4 个回复
1***@qq.com (作者)
解决了。
水灵退散
大神,怎么获取文件路径啊
e7ccode - wlizm
苹果呢?
JackietLiu
c.moveToNext()返回false。