Odin's Blog

Odin's Blog

Radio-streamer

Flash / AS 2.0Posted by Odin HG Wed, May 14, 2008 22:54:16
Radio-streamer in flash!

NOTE:
To get the URL of your stream, simply download the playlist-file (ex. .pls/.m3u). Open it in a plaintext-editor and grab the url.
The url may look similar to this:
http://193.112.14.122:8080

And remember to add ;stream.nsv after it.


Buttons:

Instancename | Description


volu | Volume Up
vold | Volume Down
nextChan | Next Channel
prevChan | Previous Channel
rndbtn | Random Channel

Actionscript in 1st frame (http://djodin.pastebin.com/f2ca64fbb):
/*******************************************
** RadioStreamer - v1.1 build 14 **
** Last build 9 May 2008 **
********************************************
** Author: Odin HG **
** Copyleft **
********************************************
** Notes: **
** Download any playlist-file, open in **
** a plain text-editor. Copy IP:PORT **
** add ";stream;nsv" (Whithout the qoutes)**
** to the stream-ip. **
** Then, add it to the chans-array. **
** chans[Channel#]=[title,ip,description] **
** use \n for linebreak in description **
*******************************************/

/* EXAMPLE-CHANNELS */
var chans = new Array();//[title,ip:port;stream.nsv,description]
chans[0] = ["Radio #1", "http://s2.viastreaming.net:7130;stream.nsv", "Latest hits.\nhttp://www.radio1.com"];
chans[1] = ["Classics", "http://193.112.14.122:8080;stream.nsv", "Classical music 24/7.\nhttp://www.classicradio.com"];
chans[2] = ["FunkRadio", "http://stream.funkradio.com:7130;stream.nsv", "Funk music!.\nVisit http://www.funkradio.com"];
/* END OF CHANNEL-ARRAY */

stream = new Sound();//Create new sound
current = 0;//Current channeø
vol = 75;//Volume

function update() {//Update channel
if (current<0) {
current = 0;
}
if (current>chans.length-1) {
current = chans.length-1;
}
stream.stop();//Stop stream
stream.loadSound(chans[current][1], true);//Load new stream
setvol();//Set new volume
_root.txtChan = chans[current][0];//Set title-text
_root.txtDesc = chans[current][2];//Set description-text
}

function setvol() {//Set volume
if (vol>100) {
vol = 100;
}
if (vol<0) {
vol = 0;
}
stream.setVolume(vol);//Set volume
}

_root.onLoad = function() {//On load
update();//Update channel
};


_root.volu.onPress = function() {//Volume up
vol += 5;
setvol();
};

_root.vold.onPress = function() {//Volume down
vol -= 5;
setvol();
};

_root.nextChan.onPress = function() {//Next channel
current += 1;//Go to next channel
update();//Update channel
};

_root.prevChan.onPress = function() {//Previous channel
current -= 1;//Go to previous channel
update();//Update channel
};

_root.rndbtn.onPress = function() {//Random channel
current = Math.round(Math.random()*(chans.length-1));//Get random channel
update();//Update channel
};


Enjoy!

  • Comments(8)http://blogg.djodin.com/#post8

Using FlashVars to pass cue points array to Flash

Flash / AS 2.0Posted by Odin HG Sun, February 24, 2008 03:18:17
In this tutorial I'll use FlashVars to pass a array containing cue points to a MediaPlayback component into flash.

In this tutorial I'm going to use it to stream mp3 files.
You can of course use it with flv files too.

First, create a new flash document (550x400), open the components window and drag a MediaPlayback component and a button to the stage.
Label the button "Cue" or what ever you want, and give it a instance name of "btn1".
Blog Image
Now, give the MediaPlayback component a instance name of "player", and go to its parameters and set contentPath to a mp3 file
(ex. http://www.example.com/my_audio.mp3).
Also set mediaType to MP3, and controlPolicy to On.

Finished?
Let's select the first frame in timeline and open the actions panel.

First add:

stop();

var cue:Array = cuepoints.split(",");
current = 0;


Explanation:

stop();

Stop the movie.

var cue:Array = cuepoints.split(",");
Create a new array of the variable cuepoints.
The split function splits the variable at every comma.
This because our variable will look something like this:
"10,40,50,200,420".
The variable cuepoints is passed trough FlashVar, I'll get back to this later.


Add this code under the previous one:

_root.btn1.onRelease = function() {
_root.player.play(cue[current]);
current++;
if (current>=cue.length) {
current = 0;
}
};


Explanation:

_root.btn1.onRelease = function() {
This line checks if the button is pressed (or here, released).

_root.player.play(cue[current]);
Tell the player to play from the next cue point in our "cue" array.

current++;
Increase the current variable with 1.
So when we press the button again, it will play from the next cuepoint in our array.

if (current>=cue.length) {
current = 0;
}
If the current cue point is greater or equal to the number of total cue points, set the first cue point as next.

};
Close the onRelease function.

Full code:
stop();

var cue:Array = cuepoints.split(",");
current = 0;



_root.btn1.onRelease = function() {
_root.player.play(cue[current]);
current++;
if (current>=cue.length) {
current = 0;
}
};


Now, go to "File -> Export -> Export Movie".
Name it "player.swf" and click "Save".
When you are going to test this local on your computer,
you'll need to set "Local playback security" to "Access network only",
IF your mp3 file is on a webserver. Else you can just let it stay at
"Access local files only".


And now, the part where we're going to pass the flashvars from html.

Create a new HTML document in the same folder as your "player.swf".
And paste this in it:

<!--[if !IE]> -->
<object type="application/x-shockwave-flash" data="player.swf" width="550" height="400">
<!-- <![endif]-->
<!--[if IE]><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="550" height="400">
<param name="movie" value="player.swf" /><!-->
<!--dgx-->
<param name="quality" value="high" />
<param name="bgcolor" value="#ffffff" />
<param name="FlashVars" value="cuepoints=10,20,30,40,50,60,70" />
<p>You need<a href="http://www.macromedia.com/go/getflashplayer" target="_blank">Adobe FlashPlayer</a> installed to view this.</p>
</object>



This is just the regular way to put flash into html, but the important line here is:

<param name="FlashVars" value="cuepoints=10,20,30,40,50,60,70" />

This is where your cuepoints is stored.

The cuepoints are given in seconds, so when you press the button the first time, it will play from 10 seconds in this example, second time 20 seconds...

If you have questions or just want to express your feelings,
post a comment below.

Odin. smiley

  • Comments(6)http://blogg.djodin.com/#post7