I'm attempting to use the chrome.getMediaGalleries
API to list the media galleries on a user's device. It works right up until the item.name
part.
I watched a video from the Google Developers youtube channel, in which they used JSON.parse
. However, that throws an Uncaught SyntaxError: Unexpected token c in JSON at position 0
as to be expected. It's not JSON.
So my question to you is: how do I retrieve the human-readable (Videos, Music, etc.). Here is my code so far:
getGalleriesInfo(/*Array of DOMFileSystem objects*/ results) {
if (!results.length)
return console.log('No galleries found');
console.log('Gallery count: ' + results.length);
results.forEach((item, index) => {
let gallery = item.name;// JSON.parse(item.name) doesn't work
console.log(index, ' => ', gallery); // 0 => chrome-extension_hmnfbbnkjlgjgmlgpacnkkndfidbejpo_0:External_media_galleries-Default-hmnfbbnkjlgjgmlgpacnkkndfidbejpo-1, etc.
});
}
// I'm using a custom element (document.registerElement)
createdCallback() {
chrome.mediaGalleries.getMediaFileSystems({
interactive: 'if_needed'
}, this.getGalleriesInfo);
}
chrome.mediaGalleries
API docsDOMFileSystem
docsJSON.parse
docs for good measureThanks,
Justin
EDIT: Chrome debugger view of item
(source: jtprogramming.com)
The chrome.getMediaGalleries API appears to have changed. To find the name of any given gallery you must use the getMediaFileSystemMetadata method.
_getGalleriesInfo(results) {
if (!results.length)
return console.log('No galleries found');
console.log('Gallery count: ' + results.length);
results.forEach((item, index) => {
console.log(chrome.mediaGalleries.getMediaFileSystemMetadata(item));
});
}
which returns an object with the metadata of the DOMFileSystem.
Object {
galleryId: (string) int,
isAvailable: boolean,
isMediaDevice: boolean,
isRemovable: boolean,
name: "C:\example\path\to\gallery"
}