Thursday Nov 12, 2009

JavaFX + Echo Nest


The Echo Nest provides series of web based solutions for better search, recommendation and interactivity on the music web. The Echo Nest API allows you to call methods that respond in REST style XML. Please refer to API documentation for more information.

They also provide a series of data feeds in various formats. Below application is updated version of DraggableMP3Player sample. Now it gets data from "Found Audio Feed" using JavaFX RssTask APIs.

<script src="http://dl.javafx.com/1.2/dtfx.js"></script> <script src="/rakeshmenonp/resource/MP3Player/MP3Player.js"></script>


To launch click on above image or

Type name of artist in TextField and press enter key. It will get the list of songs using Echo Nest feed. Click play to listen to songs! Simple! It will save the last searched artist name using JavaFX Storage APIs.

Note: Most of the media were in MP3 format (not streaming) and hence may take a while to download and play. Please try to incorporate more APIs and write new player..


<script type="text/javascript">var dzone_style = '2';</script> <script language="javascript" src="/rakeshmenonp/resource/MP3Player/zoneit.js"></script>

Tuesday Sep 15, 2009

JavaFX - Custom Feed Parsers


In one of my previous post I have described the use of RSS and ATOM Task to parse the feeds.

Unfortunately many feeds do not strictly comply with the RSS/ATOM format. Example: In some cases the date specified for pubDate element may be in wrong format, or its an invalid date or the information specified is embedded in CDATA instead of TEXT. The parser will fail for such scenarios. Hence we need to implement custom parsers so as to handle the situation.

Below sample reads engadget rss feed..

<script src="http://dl.javafx.com/1.2/dtfx.js"></script><script src="/rakeshmenonp/resource/CustomRssTask/CustomRssTask.js"></script>

For Applet mode, click on above image

Both RssTask and AtomTask API provide an attribute - factory - which can be used to specify custom implementation of RSS or ATOM Factory. Users may also customize various elements such as Channel, Item, Entry, Feed by overriding functions such as - fromXML, tryParseDate etc.

Example: In some cases the default parser fails to convert pubDate to valid DateTime instance. So a new attribute - pubDateText - is added so as to save the date as String.

/\*\*
 \* Customize Item so as to override fromXML
 \*/
class CustomItem extends Item {
    
    public-read var pubDateText : String;
    
    override function fromXML(parser: PullParser): Void {
        
        if(parser.event.qname == PUB_DATE) {
            if ((parser.event.type == PullParser.TEXTor
                (parser.event.type == PullParser.CDATA)) {
                pubDateText = stripCDATA(parser.event.text)
            }
        else if(parser.event.qname == TITLE) {
            title = stripCDATA(parser.event.text);
        else {
            super.fromXML(parser);
        }
    }
}

Now we need to implement a custom Factory which will instantiate and return the above CustomItem instance.

/\*\*
 \* Customize Factory so as to return CustomItem
 \*/
class CustomFactory extends Factory {
    public override function newItem(c: Channel: Item {
        CustomItem parent: c channel: c }
    }
}

Above Factory is set in factory attribute of RssTask as shown below.

var rssTask = RssTask {

    // set custom factory
    factory: CustomFactory { }

    location: "http://www.engadget.com/rss.xml"
    onChannel: function(channel) {  }
    onItem: function(item) { }
}
rssTask.start();

Update: Please refer to SpeedReaderFX by Jim Weaver for real world example.

Try it out and let me know feedback


<script type="text/javascript">var dzone_style = '2';</script> <script language="javascript" src="/rakeshmenonp/resource/CustomRssTask/zoneit.js"></script>

Thursday Jun 18, 2009

JavaFX - RSS and ATOM Task


JavaFX 1.2 provides new APIs to handle RSS and ATOM feeds. RssTask and AtomTask parses the feeds and provide the content as JavaFX objects. It can also be configured to provide updates on regular intervals.

RssTask parses the feed and provides the content as Channel and Item objects. These objects in-turn provides other information such as image, link, title, category, date etc.

Similarly AtomTask parses feed and provides Feed and Entry objects. These objects in-turn provides information such as author, category, link, logo, contributors etc.

News ticker using Yahoo RSS feed is given below.

<script src="http://dl.javafx.com/1.2/dtfx.js"></script><script src="/rakeshmenonp/resource/RssAtom/RssAtom.js"></script>

For Applet mode, click on above image

For standalone mode

RssTask Usage:

var rssTask = RssTask {
    
    location: "http://rss.news.yahoo.com/rss/world"
    interval: 300s

    onException: function(e) {
        e.printStackTrace();
    }

    onChannel: function(channel) {
        println("{channel.title}");
    }

    onItem: function(item) {
        println("{item.title}");
    }
}
rssTask.start();

AtomTask Usage:

var atomTask = AtomTask {
    
    location: "http://jfxstudio.wordpress.com/feed/atom"
    interval: 300s

    onException: function(e) {
        e.printStackTrace();
    }

    onFeed: function(feed) {
        println("{feed.title}");
    }

    onEntry: function(entry) {
        println("{entry.title}");        
    }
}
atomTask.start();

JavaFX Tweeter sample demonstrates use of both RssTask and HttpRequest.

Source:

<script type="text/javascript">var dzone_url = "http://blogs.sun.com/rakeshmenonp/entry/javafx_rss_and_atom_task";</script> <script type="text/javascript">var dzone_style = '2';</script> <script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script>

About


The views expressed on this blog are my own and do not necessarily reflect that of my organization

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today