Topic: Usb mp3 player

Hi!

I will try to make an offline mp3 player.
The control panel seems to access usb files and is able to play them, so the basic functionality works.

But is there any information or example how to access /mnt/usb from flash and how to play the mp3 file?
Any help would be appreciated!

Thanks!

Re: Usb mp3 player

You check the wiki? I haven't, but I imagine it would be there. I wanna follow this I find it interesting.

You could name it "controlpanel.swf" and it would override the cp with or without a connection until you pull the usb stick out, am i right? I really don't know.

Re: Usb mp3 player

I couldnt find anything about it in the wiki, but i hope they will provide some infos soon (it shouldnt be so complicated).
Another way is to decompile the current control panel...

Re: Usb mp3 player

I've added this page on how to control BTPlay from Flash - note that this only works from a local movie, not a widget.

These are the calls that the Control Panel uses to play music.

Re: Usb mp3 player

Thanks Duane, thats great!

Re: Usb mp3 player

You might also find this snippet of Actionscript handy for the enumeration of files on the USB drive.

Re: Usb mp3 player

Bump.

Whats the update on this? I'd love to see this happen!

*Hugs his Chumby*
-Tom

Re: Usb mp3 player

i played around with the file browser snippet from Duane, but couldnt get it to work.

The big problem is, that it does not run on my xp machine - maybe i am to stupid, or
maybe its cause of the missing flash lite 3 runtime environment.

And this means the whole thing is very hard to debug, cause the chumby is then a black box.
So it will take time, until i got something to work...

Re: Usb mp3 player

Sorry, that functionality *only* works on the chumby itself - it's an extension to the file:// protocol that we added.

Not sure what you mean about "chumby is a black box".  If you log into the chumby using SSH, and run your movies from a USB dongle using the command-line, you'll get all of your trace() output and more.

# cd /mnt/usb
# stop_control_panel
# chumbyflashplayer.x -i yourmovie.swf

Re: Usb mp3 player

Duane, thanks for the hint - i already got the trace statements. Testing is ok with an ssh/sftp connection (although i dont know what i have to kill to stop the controlpanel from respawning).

Nevertheless it isnt working:

The path in your snippet is "/mnt/usb", but in the controlpanel it is "//mnt/usb/" and only with this path i get stream 1 opened.
I copied now the essential parts of the controlpanel, to try exactly the same code in my environment (Flash CS3), but it isnt working either...

This is the output:

2008-03-31 00:36:07 TRACE: find
2008-03-31 00:36:07 TRACE: //mnt/usb/
2008-03-31 00:36:07 TRACE: return xml
2008-03-31 00:36:07 FileStreamRequest::Open(): Opening file '//mnt/usb/' on stream 1
2008-03-31 00:36:07 TRACE: undefined
2008-03-31 00:36:07 TRACE: find
2008-03-31 00:36:07 TRACE: MP3FilesPanelScanner.processMusic():



_global.FileFinder = function (rootDirectory)
{
    this._protocol = "file://";
    this._directories = [rootDirectory];
    this._files = [];
    this._dirXML = new XML();
    this._dirXML.ignoreWhite = true;
    this._dirXML.__target = this;
    this._dirXML.onLoad = function (success)
    {
        if (success) 
        {
            this.__target.processDirectory(this.firstChildOfType("directory"));
        }

        this._dirXML = undefined;
    }
    ;
}
;
FileFinder.prototype.processDirectory = function (dir)
{
    trace(dir);
    var base = dir.attributes.path;
    var fileItems = dir.childrenOfTypeAnd("file", this.matchFunction);
    for (var i in fileItems) 
    {
        this._files.push(base + "/" + fileItems[i].attributes.name);
    }

    var dirs = dir.childrenOfTypeAnd("directory", function (d)
    {
        return d.attributes.name.charAt(0) != ".";
    }
    );
    for (var i in dirs) 
    {
        this._directories.push(base + "/" + dirs[i].attributes.name);
    }

    if (this.find()) 
    {
        return;
    }

    this.completionFunction.call(this.target, this._files);
}
;
FileFinder.prototype.find = function ()
{
    trace("find");
    if (this._directories.length > 0) 
    {
        var dir = this._directories.pop();
        this._dirXML.load(this._protocol + dir);
        trace(dir);
        trace("return xml");
        return true;
    }

    return false;
}
;

_global.MP3FilesPanelScanner = function ()
{
    finder = new FileFinder("//mnt/usb/");
    finder.matchFunction = this.isMusicFile;
    finder.target = this;
    finder.completionFunction = this.processMusic;
    finder.find();
}
;

MP3FilesPanelScanner.prototype.isMusicFile = function (f)
{
    trace("f");
    var n = f.attributes.name;
    var ext3 = n.slice(-4);
    var ext4 = n.slice(-5);
    return n.charAt(0) != "." && ext3 == ".mp3" || ext3 == ".ogg" || ext4 == ".flac" || ext3 == ".m4a" || ext3 == ".wav";
}
;

MP3FilesPanelScanner.prototype.processMusic = function (files)
{
    trace("MP3FilesPanelScanner.processMusic(): " + files);
}
;

bLeft.onRelease = function () {
scanner = new MP3FilesPanelScanner();
};

Re: Usb mp3 player

Ah - the problem is that you also need the methods for the Object class for firstChildOfType and childrenOfTypeAnd.  Sorry I didn't include them in the snippet.

Object.prototype.firstChildOfType = function(s) {
    var n = this.firstChild;
    while (n) {
        if (n.nodeName==s) {
            return n;
        }
        n = n.nextSibling;
    }
    return null;
}

Object.prototype.childrenOfTypeAnd = function(s,f,a) {
    if (a == undefined) {
        a = new Array();
    }
    var n = this.firstChild;
    while (n) {
        if (n.nodeName==s && f(n)) {
            a.push(n);
        }
        n = n.nextSibling;
    }
    return a;
}

ASSetPropFlags(Object.prototype,"childrenOfTypeAnd,firstChildOfType",7);

Re: Usb mp3 player

great, that was the problem!
i really wonder that there is no compilation error with 2 missing functions...and also no runtime error

so lets see whats next smile

Re: Usb mp3 player

reflexnpg wrote:

i really wonder that there is no compilation error with 2 missing functions...and also no runtime error

That's not really possible in a pure prototype-based language like ECMAscript/AS1.  However, AS2 is much more picky and will throw compile-time errors for missing class methods, at the expense of flexibility.

reflexnpg wrote:

....(although i dont know what i have to kill to stop the controlpanel from respawning)

The "stop_control_panel" script takes care of shutting down the watchdog that respawns the Control Panel.

Re: Usb mp3 player

Duane, i got it running, but there is one thing missing:

how can i create an m3u file from flash?
or how can i feed the playlist into the pipe of btplay?

i've found the function

_putFile = ASNative(5, 51);

but it isnt working somehow....

Please help!

Re: Usb mp3 player

An m3u file won't help because btplay can't use them directly.

There actually is a simple playlist manager in btplayd - I've added the ASnatives to the wiki page for btplay.

Hope they work for you.

Re: Usb mp3 player

_AddToPlaylist = ASnative(5,149);

is not working.
I tried:

_AddToPlaylist("/mnt/usb/Candy.mp3");

and i got:

2008-04-02 23:49:46 TRACE: //mnt/usb/Candy.mp3
2008-04-02 23:49:46 BtplayPlaylist: required argument(s) missing

Nevermind, i will try keep the playlist on my side, so i can better control shuffle and repeat...
Where can i post the prototype?

Re: Usb mp3 player

Oh please post it soon, I really wanna check it out, even basic function would be fantastic to me!

Re: Usb mp3 player

reflexnpg wrote:

_AddToPlaylist = ASnative(5,149);

is not working.
I tried:

_AddToPlaylist("/mnt/usb/Candy.mp3");

and i got:

2008-04-02 23:49:46 TRACE: //mnt/usb/Candy.mp3
2008-04-02 23:49:46 BtplayPlaylist: required argument(s) missing

Ah, sorry, I had an error on that page, which I've corrected.  This call requires the first parameter to be the mimetype of the files, which mean you need at least two parameters.

19 (edited by reflexnpg 2008-04-04 12:40:11)

Re: Usb mp3 player

Duane, thanks for the info!

I have some more questions:

- is it possible to get the length of the song?
- how to change the volume?
- whats the best place for posting the prototype?

From the wiki page:

_SongAttributes = ASnative(5,135);
attrs = _SongAttributes();

returns XML of the information about the currently playing track, typically MP3 tags and other metadata

But it does only return:

2008-04-04 22:36:47 TRACE: Tags/Title=I Can't Make You Love Me
Tags/Artist=Candy Dulfer
Tags/Album=Sax-A-Go-Go
Tags/Year=93
Tags/Comment=
Tags/Genre=R&B
Tags/Index=1


its not a valid xml i think...

Re: Usb mp3 player

@Beastlykings:
you can try the prototype of my mp3 player:
http://rapidshare.com/files/105162743/RxPlayer.rar

shuffle and repeat are broken. use at own risk.
if you still want to test, then just extract the archive to a usb stick with mp3 files on it.

Re: Usb mp3 player

Wow thats great! Impressed!
I was having major problems with it restarting periodically, and when doing so would not not let me play any songs. It was retarded and I couldn't figure it out, Well I was letting the chumby start it, with the controlpanel naming option. It seems the chumby was killing/restarting it. Should it do this? have you had this problem? Can I stop it?

When I started it manually it worked GREAT! If just a prototype, its a great one. I haven't tried the shuffle/repeat.

Thanks for the work on it! Loving it!

-Tom

Re: Usb mp3 player

Cool!! Works Well. Will Is there ff and rewind? Much better than the My Music files function!

Re: Usb mp3 player

muks wrote:

Cool!! Works Well. Will Is there ff and rewind? Much better than the My Music files function!

As he said, those two functions don't work yet. but I imagine they will be resolved soon enough

Re: Usb mp3 player

It plays a few songs and then starts from the first again....am I doing something wrong?
Thanks

25 (edited by Beastlykings 2008-04-16 07:12:11)

Re: Usb mp3 player

muks, it uses a playlist type function, it doesn't play directories. You have to load the playlist with the songs you choose using the arrow key type deal.. Shouldn't be too hard to figure out. smile

EDIT: Oh I see what you meant.. My bad.. I think thats the problem I had, renaming it "controlpanel.swf" and letting the chumby do it was for some reason causing it to reset after a few minutes. So I used a debugchumby file instead. But now I'm starting to have with which starts it freezes.. Idk, still prototype.