This is a neat little snippet. It is basically the toolbox for your playlist. You can add or remove files, use it as an easy $findfile and load your playlist into a dialog. There are two sides to the snippet:
One - Returned as an identifier for your playlist. Basically a $findfile in a different form.
Two - Returned as an alias for adding files or removing files.
Tables:
pfile - returns the file you aim to play or use in your mp3.
$fmp3params(pfile,filename,1) - /fmp3params pfile rem (filename) - /mp3params pfile add
Newdir - changes your default directory /fmp3params newdir
load - loads a playlist into a dialog /fmp3params load
See the code below for an example. ;)
alias fmp3params {
if (!$exists(playlist.txt)) {
var %x = $sdir($mircdir), %y = 1
while ( $findfile(%x,*.mp3,%y) ) {
write playlist.txt $findfile(%x,*.mp3,%y) | inc %y
}
set %mp3dir %x
}
else {
if ($1 = pfile) && ($2) {
var %c = $read(playlist.txt,$2)
if ($3 iswm 1) return %c
if ($3 iswm rem) write -dl playlist.txt %c
if ($2 iswm add) write playlist.txt $$sfile($readini(%mp3dir, Choose a file to add:)
}
if ($1 = load) && ($dialog($2)) {
var %y = 1
while ($read(playlist.txt,%y)) {
did -a $2 $3 $remove($nopath($read(playlist.txt,%y)),.mp3) | inc %y
}
}
if ($1 = newdir) {
var %x = $sdir($mircdir), %y = 1
write -c playlist.txt
while ( $findfile(%x,*.mp3,%y) ) {
write playlist.txt $findfile(%x,*.mp3,%y) | inc %y
}
set %mp3dir %x
}
}
}
dialog mp3d {
title "Mp3 player"
size -1 -1 232 142
option pixels
list 1, 3 3 174 136, size
button ">>", 2, 179 10 45 25
button "<<", 3, 179 111 45 25
button "||", 4, 179 35 45 25
button "|>", 5, 179 61 45 25
button "", 6, 179 86 45 25
}
on *:dialog:*:*:*:{
if ($dname iswm mp3d) {
if ($devent iswm init) {
fmp3params load $dname 1
}
if ($devent iswm sclick) {
if ($did iswm 5) { splay -p $fmp3params(pfile,$did($dname,1).sel,1) }
if ($did iswm 2) { did -c $dname 1 $calc($did($dname,1).sel + 1) | splay -p $fmp3params(pfile,$did($dname,1).sel,1) }
if ($did iswm 3) { did -c $dname 1 $calc($did($dname,1).sel - 1) | splay -p $fmp3params(pfile,$did($dname,1).sel,1) }
if ($did iswm 4) {
var %i = $iif(%c = true, $true, $false)
if (%i iswm $false) && ($inmp3) { %c = true | splay pause | halt }
if (%i iswm $true) { unset %c | splay resume | halt }
}
if ($did iswm 6) && ($inmp3) { splay stop }
}
}
}