How to access external Storage in Tizen Smart TVs

2.9k views Asked by At

I need yout help to find out how to write and read files from external usb storage from Tizen Smart TVs. Problem starts when detecting it

`
/**
 * Hello World Sample Project
 */
// import Label component
var Label = caph.require('ui.base.component.Label');

caph.app.addScene('main', $class({
    $extends : caph.require('ui.base.Scene'),

    // oncreate is called when the scene is created
    oncreate : function() {
        // add "Hello World"

        this.addChild(new Label({
            text : 'Hello World',
            size : [ 500, 100 ],
            position : [ 300, 400 ]
        }).setTextSize('72px').setStyle({
            backgroundColor : 'red',
            color : 'white'
        }));

        /// Here the filesystem showd show me all the storages
        tizen.filesystem.listStorages(checkCorruptedRemovableDrives);
    }
})).run();
`

And here is the Success callback, this show me how much storages I have. ` /* Success event handler */ var checkCorruptedRemovableDrives = function(storages) {

    /// Here I will kow how much storages I have
    console.log(storages.length);

    for (var i = 0; i < storages.length; i++) {
        if (storages[i].type != "EXTERNAL")
            continue;
        if (storages[i].state == "UNMOUNTABLE")
            console.log("External drive " + storages[i].label + " is corrupted.");
    }
};
`

Here is the method thrown when there are errors, this is never called. var checkCorruptedRemovableDrivesError = function(storages){ console.log("Error"); }

Now, the console output is aways a simple 0 meanning I have no storage (but I have the internal one and two usb ones mounted).

Has Anyone faced this problem or have any Idea on how to solve it?

2

There are 2 answers

0
Lee Hojin On BEST ANSWER

Samsung Tizen TV always uses "removable2" as label for USB. So you don't need to use listStorage and getStorage.

Multiple USBs are distinguished as "removable2/sda1", "removable2/sda2"

tizen.filesystem.resolve("removable2", function(e){
        e.listFiles(function(r){
            for(i = 0; i < r.length; i++){
                tizen.filesystem.resolve(r[i].path + r[i].name, function(t){
                    //You resolve USB root. Do something you want with USB.
                }, function(t){
                    console.log("resolve error for " + r[i].path + r[i].name);
                    console.log(t);                
                }, "rw"); //you should use rw permission, to write something in usb.
            }
        });               
    },function(e){
        console.log("removable2 resolve error");
        console.log(e);
    }, "r"); // permission should be given as r for removable2

Here is test app made by me. and you can check how to use SDK 1.5

http://www.samsungdforum.com/SamsungDForum/ForumView/3ad8bd6023af18a7?forumID=d88a711f47dc6e9f

This app is working in both of TV and SDK 1.5

2
Lee Hojin On

Do you use Web Simulator? APIs don't work in Web Simulator properly. It can't simulate things well.

When I check listStorage in 'emulator', it throws list of storages. but even though I can get list of storage, I can't use it in filesystem. It is bug of SDK 1.4.

SDK 1.5 will have test features for USB storage, and it is planned to release in a month. Wait for a month :(