JSON / XML Playlist Support

The API provides support for parsing XML/JSON based playlist formats. Currently only ASX, XSPF and JSPF playlist formats are supported.

The required module

Your application should inherit the com.bramosystems.oss.player.playlist.Playlist module for this to work.

The playlist parser factory

The com.bramosystems.oss.player.playlist.client.PlaylistFactory class provides static methods to parse the supported plalist formats to POJO objects. The POJO objects provide methods and properties to access the underlying data.

Working with playlists

Assuming we have the following playlist in JSPF format generated by some server side code (it is also possible to have it as a JSON file anyway):

{
    "playlist" : {
        "title"         : "Sample JSPF Playlist Example",
        "creator"       : "Sikiru Braheem",
        "annotation"    : "Sample playlist created for BST Player API",
        "info"          : "http://oss.bramosystems.com/bst-player",
        "location"      : "http://oss.bramosystems.com/bst-player/demo/showcase/",
        "identifier"    : "201106_playlists_jspf",
        "date"          : "2011-05-08T17:10:47+01:00",
        "license"       : "http://creativecommons.org/licenses/by/3.0/",
        "track"         : [
            {  "location"      : ["applause.mp3"],
            "identifier"    : ["idx1"],
            "title"         : "Applause",
            "creator"       : "Unknown",
            "annotation"    : "Just an applause",
            "album"         : "Sample Playlist",
            "trackNum"      : 1,
            "duration"      : 5000 },

            {   "location"      : ["big-buck-bunny.mp4"],
            "identifier"    : ["idx2"],
            "title"         : "Big Buck Bunny",
            "creator"       : "Blender Foundation | www.blender.org",
            "annotation"    : "Big Buck Bunny Preview",
            "info"          : "www.bigbuckbunny.org",
            "album"         : "Sample Playlist",
            "trackNum"      : 2,
            "duration"      : 60000 },

            {   "location"      : ["traffic.flv"],
            "identifier"    : ["idx3"],
            "title"         : "Evening traffic shot",
            "creator"       : "Sikiru Braheem",
            "annotation"    : "Evening Traffic Shot",
            "info"          : "sbraheem /at/ bramosystems /dot/ com",
            "album"         : "Sample Playlist",
            "trackNum"      : 3,
            "duration"      : 10000 }
        ]
    }
}

The example below illustrates how to use the playlist with the player widgets:

RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, 
        "http://example.com/playlists/sample-playlist-in-jspf-format.json");
rb.sendRequest(null, new RequestCallback() {

public void onResponseReceived(Request request, Response response) {
    // parse playlist data to SPFPlaylist object
    SPFPlaylist pl = PlaylistFactory.parseJspfPlaylist(response.getText());

    // once available we can work with the various fields ...
    GWT.log("Playlist Title   : " + pl.getTitle());
    GWT.log("Playlist Creator : " + pl.getInfo());

    // see the entries in the playlist ...
    JsArray<Track> ts = pl.getTracks();
    for (int i = 0; i < ts.length(); i++) {
        Track t = ts.get(i);
        GWT.log("Track Title   : " + t.getTitle());
        GWT.log("Track Creator : " + t.getCreator());
        GWT.log("Track URL     : " + t.getLocation());
    }

    // if we had an existing player widget, we can add this playlist 
    // to the player as well ...
    playerWidget.addToPlaylist(pl.toPlaylist());
}

public void onError(Request request, Throwable exception) {}
});

Other supported playlist formats can be used in a similar way with the PlaylistFactory.