Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by EternallyCurious. 04/18/24 10:45
StartWeek not working as it should
by Zheka. 04/18/24 10:11
folder management functions
by VoroneTZ. 04/17/24 06:52
lookback setting performance issue
by 7th_zorro. 04/16/24 03:08
zorro 64bit command line support
by 7th_zorro. 04/15/24 09:36
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:48
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:46
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (EternallyCurious, howardR), 646 guests, and 0 spiders.
Key: Admin, Global Mod, Mod
Newest Members
EternallyCurious, 11honza11, ccorrea, sakolin, rajesh7827
19046 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Improved playlist with random and normal play.. #111648
02/11/07 11:03
02/11/07 11:03
Joined: Dec 2006
Posts: 1,086
Queensland - Australia
Nidhogg Offline OP
Serious User
Nidhogg  Offline OP
Serious User

Joined: Dec 2006
Posts: 1,086
Queensland - Australia
I hope I am allowed to post the code here. Anyway, here is my contribution to the GS community...

//playlist.wdl
/* Improved version of my first PLAYLIST.M3U reading template.
I have tested this template with the 3DGS A65.06 Pro version so I don't know
if it will work with earlier version hmmm OK..
I also cannot take full credit for bits of this code as I
did have some help from people who where kind enough to give me
ideas and even bits of working code to use, Also a afew bits from other
tutorial code. So credit to where credit is due and a big thankyou....

This template should work with most playlists maybe change
the code in the Check_For_Music function part.

I am aslo working on a DLL version but it will have more features...
Will take a while though as I am only still a youngun when it comes
to C++ lol...

The only thing I ask for in return is a small credit in any 3DGS release thanks...

Kindest regards Andrew Sengstock..
Alias Nidhogg....
*/


string rfile_str[256]; //For Random Play
string sfile_str[256]; //For Normal Play

var slot; //Used in Random function
var splay = 0; //Used in Normal Play
var rplay = 1; //Used in Random Play
var filehandle; //A file handle for loading and reading
var muhandle; //Handle used to detect if media is playing
var randlist; //Another Random Play var
var DontPlayMusic = 0; //Don't play media if not correct playlist format
/////////////////////////////////////////////////////////////////

FONT song_font , <Arial10.bmp>, 10, 16;

text song_txt // text object for displaying our strings
{
font = song_font; // standard font
pos_x = 10; // text begins at (10, 10) screen position (in pixels)
pos_y = 26;
}
/////////////////////////////////////////////////////////////////

text stay_txt // text object for displaying our strings
{
font = song_font; // standard font
pos_x = 10; // text begins at (10, 10) screen position (in pixels)
pos_y = 12;
}
/////////////////////////////////////////////////////////////////

function songprint(str) // display a string parameter on the screen
{
song_txt.string = str;
song_txt.visible = on;
Wait(100); //Stay on screen this long...
song_txt.visible = off;
}

function status_print(str) // display a string parameter on the screen
{
stay_txt.string = str;
stay_txt.visible = on;
Wait(100); //Stay on screen this long...
stay_txt.visible = off;
}
/////////////////////////////////////////////////////////////////

function song_show()
{
//screen_color.blue = 128; // set a dark blue background
if (splay == 0)
{
songprint(sfile_str); // display the string
}
else
{
songprint(rfile_str); // display the string
}
}

/////////////////////////////////////////////////////////////////

function Open_Playlist()
{
//Opens playlist the playlist file for reading...
filehandle = file_open_game("playlist.m3u");
}
/////////////////////////////////////////////////////////////////

function Close_Playlist()
{
//Closes the playlist file...
file_close(filehandle);
}
/////////////////////////////////////////////////////////////////

Function Check_For_Music()
{
Open_Playlist();
file_str_read(filehandle,sfile_str);
if str_cmp(sfile_str,"#EXTM3U") == 0
{
DontPlayMusic = 1;
status_print(" Invalid M3U playlist, Exiting program!");
sleep(5);
sys_exit(" ");
};
Close_Playlist();
}
/////////////////////////////////////////////////////////////////

function change_mode() //Changes between Random and Normal play via assigned ON_F2 Key
{ //eg: ON_F2 change_mode();
If (media_playing(muhandle) == 1)//If media is playing
{
media_stop(muhandle);//Stop media
muhandle = 0;//Reset var back to 0
}

if (splay == 0) //If we are in Normal Play mode
{
splay = 1; //Change var to 1
rplay = 0;//Ok now we go to Random Play
}
else
{
splay = 0; //If we are Random
rplay = 1; //Go back to Normal
}
}
/////////////////////////////////////////////////////////////////

function Random_play()
{
rplay = 0;
splay = 1;

status_print("Random Play");

If (media_playing(muhandle) == 1)
{
media_stop(muhandle);
muhandle = 0;
}

If (media_playing(muhandle) == 0)//If no media is playing
{
randomize(); //Start random
slot = 0; //Set slot to 0
randlist = 0;//Set the list to zero
Open_Playlist();
randlist = int(random(243));//Set this to how many actual MP3's in your playlist file. Not sure what the MAX would be..
while (slot != randlist) //Start the Loop
{
freeze_mode = 1; //Stop graphics, You don't have to have this..
file_str_read(filehandle,rfile_str);//Start reading individual lines in the playlist..
if (str_cmpni(rfile_str,"#") == 0)//Check if it's an actual file or path to file. If Not
{
file_str_read(filehandle,rfile_str);//Read the next line..
slot += 1;//Ok add it to the counter.
}
}//Keep looping until the slot matches the random randlist number..
// Close_Playlist(); Leave commented out..
wait(1);//Wait 1 frame or else we can get an error..
media_play(rfile_str,null,100);// Start playing the chosen Random file..
muhandle = media_handle;//Assign our error handle for media_play
songprint(rfile_str);//Horrible version of what file is playing, Until I finish the DLL..
freeze_mode = 0;//Ok now start the graphics again..
}
}
/////////////////////////////////////////////////////////////////
function Single_Play()// Pretty much the same as random play, But does Line for Line play of files..
{
splay = 0;
rplay = 1;

status_print("Normal Play");

If (media_playing(muhandle) == 1)
{
media_stop(muhandle);
muhandle = 0;
}

If (media_playing(muhandle) == 0)
{
file_str_read(filehandle,sfile_str);
while (str_cmpni(sfile_str,"#") == 0)
{
freeze_mode = 1;
file_str_read(filehandle,sfile_str);
wait(1);
if (str_len(sfile_str) == 0) //At the end of the list so we
{ //Skip back to beginning by closing and reopening the playlist file.
Close_Playlist();
wait(1);
Open_Playlist();
wait(1);
}
else
{
media_play(sfile_str,null,100);
muhandle = media_handle;
songprint(sfile_str);
freeze_mode = 0;
break; //Need to put a break out of loop here, Otherwise it wouldn't stop looping.
}
}
}

}
/////////////////////////////////////////////////////////////////

function Get_songs()
{
Open_Playlist();

while(1)
{
if (splay == 0) //Are we Normal Playing
{
splay = 0;
rplay = 1;
If (media_playing(muhandle) == 0)
{
Single_Play();
}
}
if (rplay == 0) //Or Random Playing
{
splay = 1;
rplay = 0;
If (media_playing(muhandle) == 0)
{
// Close_Playlist();
Random_Play();
}
}
wait(1);
}
}
////////////////////////////////////////////////////////////////////

function paused() //Pause the program via an ON_F? assigned key.
{
media_pause(muhandle);
freeze_mode = 1;
wait(1);
}
////////////////////////////////////////////////////////////////////

function restart() //As above but restart from where it paused..
{
media_start(muhandle);
freeze_mode = 0;
wait(1);
}
////////////////////////////////////////////////////////////////////

function Skip_song()//Don't like the song playing, Lets skip it, via an ON_K? assigned key
If (media_playing(muhandle) == 1)
{
media_stop(muhandle);
muhandle = 0;
wait(1);
}
////////////////////////////////////////////////////////////////////

Enjoy, Oh and if you wouldn't mind, A comment wouldn't go astray.


Windows XP SP3
Intel Dual Core CPU: E5200 @ 2.5GHz
4.00GB DDR3 Ram
ASUS P5G41T-M LX
PCIE x16 GeForce GTS 450 1Gb
SB Audigy 4
Spyware Doctor with AntiVirus
Re: Improved playlist with random and normal play. [Re: Nidhogg] #111649
02/11/07 14:47
02/11/07 14:47
Joined: May 2005
Posts: 155
C:\Program files\GStudio6
alphaindigo Offline
Member
alphaindigo  Offline
Member

Joined: May 2005
Posts: 155
C:\Program files\GStudio6
yeah food stuff, i would have posted it in user contributions, this forum is for discussing the templates that come with gamestudio. still a good contrib though!


beware the sock! - tLempoary...
Re: Improved playlist with random and normal play. [Re: alphaindigo] #111650
02/14/07 06:53
02/14/07 06:53
Joined: Dec 2006
Posts: 1,086
Queensland - Australia
Nidhogg Offline OP
Serious User
Nidhogg  Offline OP
Serious User

Joined: Dec 2006
Posts: 1,086
Queensland - Australia
Thankyou for moving it.. I'll remember in the future..


Windows XP SP3
Intel Dual Core CPU: E5200 @ 2.5GHz
4.00GB DDR3 Ram
ASUS P5G41T-M LX
PCIE x16 GeForce GTS 450 1Gb
SB Audigy 4
Spyware Doctor with AntiVirus
Re: Improved playlist with random and normal play. [Re: Nidhogg] #111651
02/14/07 14:11
02/14/07 14:11
Joined: Jul 2006
Posts: 783
London, UK
sheefo Offline
User
sheefo  Offline
User

Joined: Jul 2006
Posts: 783
London, UK
I could use this for background music in my RTS game . Thanks for contributing. I will credit you.

Re: Improved playlist with random and normal play. [Re: sheefo] #219104
08/01/08 01:25
08/01/08 01:25
Joined: Nov 2006
Posts: 5
X
xeno2k4ever Offline
Newbie
xeno2k4ever  Offline
Newbie
X

Joined: Nov 2006
Posts: 5
can this be used in a7?

Re: Improved playlist with random and normal play. [Re: xeno2k4ever] #219138
08/01/08 07:50
08/01/08 07:50
Joined: Dec 2006
Posts: 1,086
Queensland - Australia
Nidhogg Offline OP
Serious User
Nidhogg  Offline OP
Serious User

Joined: Dec 2006
Posts: 1,086
Queensland - Australia

I did a rebuild with A7.10.1 and it worked for like 3 to maybe 4 hours then it crashed. So a few very minor change in a couple of places should solve this.

I haven't the time at the moment to do it as I am working on a bigger project.


Windows XP SP3
Intel Dual Core CPU: E5200 @ 2.5GHz
4.00GB DDR3 Ram
ASUS P5G41T-M LX
PCIE x16 GeForce GTS 450 1Gb
SB Audigy 4
Spyware Doctor with AntiVirus
Re: Improved playlist with random and normal play. [Re: Nidhogg] #219243
08/01/08 15:47
08/01/08 15:47
Joined: Mar 2006
Posts: 2,758
Antwerp,Belgium
frazzle Offline
Expert
frazzle  Offline
Expert

Joined: Mar 2006
Posts: 2,758
Antwerp,Belgium
This looks like a pretty handy UC Nidhogg smile smile
Btw, it would have been handy/more attractive if you had made a demo level of it and zipped it wink wink

Cheers

Frazzle


Antec® Case
Intel® X58 Chipset
Intel® i7 975 Quad Core
8 GB RAM DDR3
SSD OCZ®-VERTEX2 3.5 x4 ; HD 600 GB
NVIDIA® GeForce GTX 295 Memory 1795GB
Re: Improved playlist with random and normal play. [Re: frazzle] #219287
08/01/08 16:42
08/01/08 16:42
Joined: Dec 2006
Posts: 1,086
Queensland - Australia
Nidhogg Offline OP
Serious User
Nidhogg  Offline OP
Serious User

Joined: Dec 2006
Posts: 1,086
Queensland - Australia
I did wink And thanks for the comment.


Windows XP SP3
Intel Dual Core CPU: E5200 @ 2.5GHz
4.00GB DDR3 Ram
ASUS P5G41T-M LX
PCIE x16 GeForce GTS 450 1Gb
SB Audigy 4
Spyware Doctor with AntiVirus

Moderated by  adoado, checkbutton, mk_1, Perro 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1