How to create an Empty Playlist File on Mac?
Hello everyone, I'm working on a Music Player script, I was able to play a file via the default player as when we doubleclick on a file. The problem is I have no control over the Player, so to "stop" a file I could play a "silent" mp3, one with 1 second of silence in it for example. I discarded the idea since I had to distribute this silent.mp3 file along with the script. A better option is to play a "playlist", since playlist files are text only, I could create them an empty playlist file on the fly...
so, the question is, what's the default playlist extension on a mac? and how to create one on the Mac?
in windows the default player is Windows Media Player, the default playlist file extension is *.wpl.
here's the contents of an empty playlist
<?wpl version="1.0"?>
<smil>
<head>
<meta name="Generator" content="Microsoft Windows Media Player -- 12.0.7601.18150"/>
<meta name="ItemCount" content="0"/>
<title>empyPlaylist</title>
</head>
</smil>
here's the script, so far Windows only, at least to stop the file being played.
// script.name = musicPlayer_Windows.jsx;
// script.needs = I need to create an Empty Playlist File for the Mac, that will play on the default music player when executed
// carlos canto, 10/12/2014
var w = new Window('dialog', 'Music Player');
var btnFile = w.add('button', undefined, 'Select an *.mp3 file to play...');
var lblSong = w.add('edittext', undefined, '');
lblSong.characters = 30;
var btnPlay = w.add('button', undefined, 'Play');
var btnStop = w.add('button', undefined, 'Stop');
var btnClose = w.add('button', undefined, 'Close');
btnPlay.enabled = btnStop.enabled = false;
var emptyPlaylist = getEmptyPlaylist ();
btnFile.onClick = function () {
var file = File.openDialog ("Select File to Play...", '*.mp3', false);
lblSong.text = file.displayName;
lblSong.file = file;
btnPlay.enabled = btnStop.enabled = true;
}
btnPlay.onClick = function () {
lblSong.file.execute();
$.sleep (300);
BridgeTalk.bringToFront('estoolkit');
}
btnStop.onClick = function () {
emptyPlaylist.execute();
$.sleep (300);
BridgeTalk.bringToFront('estoolkit');
}
btnClose.onClick = function () {
w.close();
}
w.show();
// this function creates an Empty Playlist file (Windows) on the fly, this file will be used to "stop" a playing file
// I need a similar function for Mac
function getEmptyPlaylist () {
var desk = Folder.desktop;
var f = new File(desk+'/emptyPlaylist.wpl');
if (!f.exists) {
var s_emptyPlaylist = (new String("<?wpl version=\"1.0\"?>\n<smil>\n <head>\n <meta name=\"Generator\" content=\"Microsoft Windows Media Player -- 12.0.7601.18150\"/>\n <meta name=\"ItemCount\" content=\"0\"/>\n <title>empyPlaylist</title>\n </head>\n</smil>\n"));
f.encoding = 'utf-8';
f.open('w');
f.write(eval(s_emptyPlaylist));
f.close();
}
return f;
}
thanks in advance
Carlos
