Skip to content
Aug 20 / Sidney de Koning

AS3 PLS (Playlist ) reader updated!

Just updated some final functionality on my as3plsreader/writer. As you can read from the comments here, someone actually is using it :)

As requested I have put in M3U file support, and rewritten the parser so it is really fast (using RegExp).

So check out the project using SVN, play around with it and tell me what you think!

Below is a example of how easy it works:

import nl.funkymonkey.firelog.core.Logger;
import nl.funkymonkey.utils.io.playlist.events.ParseEvent;
import nl.funkymonkey.utils.io.playlist.*;
import nl.funkymonkey.utils.io.playlist.types.*;

var _url:String="http://www.funky-monkey.nl/air/plstest/playlist.m3u";
buildFromOnline();
function buildFromOnline():void {

	var loader : URLLoader = new URLLoader();
	loader.addEventListener(Event.COMPLETE, plsLoaded);
	loader.addEventListener(ProgressEvent.PROGRESS, onProgress);
	loader.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
	loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onSecurityError);
	loader.addEventListener(HTTPStatusEvent.HTTP_STATUS, httStatus);

	loader.load(new URLRequest(_url));
}

function plsLoaded( e : Event ):void {

	var value:String=e.currentTarget.data;

	// Create a new file from string data
	var plsFile:File=File.desktopDirectory;
	plsFile.url+= "/playlist.m3u";
	Logger.info("url: " + plsFile.url);
	Logger.info("nativePath: " + plsFile.nativePath);
	var fs : FileStream = new FileStream();
	fs.open(plsFile, FileMode.WRITE);
	fs.writeUTFBytes(value);
	fs.close();

	Logger.info("====== PLS# " + plsFile + " ======");
	// instanciate new PlayListReader object with file reference
	var pls : PlaylistReader = new PlaylistReader();
	pls.addEventListener(ParseEvent.FILE_PARSED, parsedPlaylist, false, 0, true);
	pls.source=plsFile;
}

function parsedPlaylist( evt:ParseEvent):void {

	var m3uFile:Array=evt.fileData as Array;
	Logger.info( "file with extension " + evt.extension.toString( ) + " succesfully parsed." );
	Logger.info( "====== M3U FILE   " + m3uFile.toString( ) + " ======" );

	for (var i:int = 0; i < m3uFile.length; ++i) {

		Logger.info( "====== M3U Item no# " + (i + 1) + " of " + m3uFile.length + " ======" );
		Logger.info( "** file   : " + IPlayable(m3uFile[i]).file );
		Logger.info( "** title  : " + IPlayable(m3uFile[i]).title );
		Logger.info( "** length : " + IPlayable(m3uFile[i]).length );
		Logger.info( "** isStream: " + IPlayable(m3uFile[i]).isStream );
	}
}
function httStatus( e : HTTPStatusEvent ):void {
	Logger.info(e.status);
}

function onProgress( e : Event ):void {
	Logger.info(e);
}

function onIOError( e : IOErrorEvent ):void {
	Logger.info(e.text);
}

function onSecurityError( e : Event ):void {
	Logger.info(e);
}

Please consider to buying me a coffee.

3 Comments

Leave a comment
  1. Andrei Potorac / Aug 28 2009

    Hey, thanks for this, it’s really useful! :D

  2. Eric Dolecki / Jan 26 2010

    Could you contact me – what Logger are you using? I could write my own, but it might be nice just to download the SWF you’re using to capture the log data.

  3. Metacowboy / Nov 23 2011

    Great work quite a time ago but very nice one only i would sugest to add a other m3u link as that one will return a error on non windows. PlaylistReader.as
    and for eric the logger is in the repositiroy

Leave a comment