Thursday, March 18, 2010

Create a MP3 Player for iPhone and Android Using GWT and Titanium

Titanium is a tool provide by appcelerator.com, which allow you to transform web application into native iPhone or Android App. I try to play around a little and I create a MP3 Player in GWT, which can be export on iPhone or Android.

Here is the code (See how it's simple) :

public class Player extends Composite implements ClickHandler
{
private VerticalPanel _vpanel;
private HorizontalPanel _hPanel;
private TextBox _box;
private Button _play;
private Button _stop;
private Sound _sound;
public Player()
{
this._hPanel = new HorizontalPanel();
this._box = new TextBox();
this._play = new Button();
this._play.addClickHandler(this);
this._play.setHTML("Play !");
this._hPanel.add(this._play);
this._stop = new Button();
this._stop.addClickHandler(this);
this._stop.setHTML("Stop !");
this._hPanel.add(this._stop);
this._vpanel = new VerticalPanel();
this._vpanel.add(this._box);
this._vpanel.add(this._hPanel);
initWidget(this._vpanel);
this._sound = null;
}


public void onClick(ClickEvent event)
{
if (event.getSource() == this._play)
{
this._sound = new Sound(this._box.getValue());
this._sound.play();
}
if (event.getSource() == this._stop)
{
if (this._sound != null)
{
this._sound.pause();
}
}
}
}

No comments:

Post a Comment