Membuat Player Live Radio Streaming


Bagi yang ingin mencoba untuk membuat player media streaming atau radio live streaming silahkan coba kelas di bawah ini.

Ini adalah kelas untuk membaca radio streaming:

package radio;

import javafx.scene.media.*;

/**
* @author bhangun
* Created on Nov 7, 2009, 8:14:21 AM
*/
public class Radio {
/**
URL stasion radio
*/
public-init var stationURL:String;

var mediaPlayer:MediaPlayer = MediaPlayer {
volume: 0.5
autoPlay: true
onError: function(e:MediaError) {
println(“MediaPlayer error : {e.cause} {e}”);
closeRadio();
}
onEndOfMedia: function() {
println(“end session {bufferedTime}”);
}
};
var media:Media = null;
// the time control slider
var time_control_length = 240.0;
var time_control_xoff = 210;

public var currentTime = bind
if (mediaPlayer.media != null and
mediaPlayer.media.duration != null and
mediaPlayer.media.duration.toMillis() > 0 and
mediaPlayer.currentTime.toMillis() > 0)
{
time_control_length * mediaPlayer.currentTime.toMillis() / mediaPlayer.media.duration.toMillis()
} else {
0.0
};
public var bufferedTime = bind
if (mediaPlayer.media != null and
mediaPlayer.media.duration != null and
mediaPlayer.media.duration.toMillis() > 0 and
mediaPlayer.bufferProgressTime.toMillis() > 0)
{
time_control_length * mediaPlayer.bufferProgressTime.toMillis() / mediaPlayer.media.duration.toMillis()
} else {
0.0
};
function getMedia():Media {
if (media == null) {
println(“Loading radio streaming: {stationURL}”);
media = Media {
source: “{stationURL}”
onError: function(e:MediaError) {
println(“terjadi error {e}”);
}
}
}
return media;
}

/**
*
*/
public function closeRadio():Void {
if (media != null) {
media.source = null;
media = null;
}
}

public function playRadio():Void {
mediaPlayer.media = getMedia();
mediaPlayer.play();
}

public function pauseRadio():Void {
mediaPlayer.pause();
}
}

Untuk mencobanya jalankan contoh kode berikut;

var radio:Radio = Radio{
stationURL:”http://hizbut-tahrir.or.id:8000″
}
radio.playRadio();
println(radio.bufferedTime);

Selamat mencoba!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: