Gamestudio Links
Zorro Links
Newest Posts
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Help with plotting multiple ZigZag
by M_D. 04/26/24 20:03
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
M1 Oversampling
by jcl. 04/26/24 11:12
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
Eigenwerbung
by jcl. 04/26/24 11:08
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (1 invisible), 735 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
wandaluciaia, Mega_Rod, EternallyCurious, howardR, 11honza11
19049 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
A simple music system example script ( wav, mp3, ogg ... ) #439129
03/27/14 11:26
03/27/14 11:26
Joined: Jul 2008
Posts: 2,107
Germany
rayp Offline OP

X
rayp  Offline OP

X

Joined: Jul 2008
Posts: 2,107
Germany
And again me...

I made this example of an simple music - player system. It features volume fading between songs etc.
If u optimize something: POST!

Code:
// ----------------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------------
/* 27.03.2014
   ----------------------------------------------------------------------------------------------
   music - system (ms) example script         rayp 2014  free2use   forum:www.coniserver.net/ubb7
   ----------------------------------------------------------------------------------------------
   You can simply add more songs. CopyNPaste MS_SongX and the "if (_ms_song_newsong == X... -
   line" and count up :D see example MS_Song3
   Note: switching songs ingame : _ms_song_newsong = Number of newsong 0 for none ... thats it !
         call "_init_music_system();" once, and have fun !
         set _mm_music_on to 1 be4 calling !
   example needs: song1.mp3 and song2.mp3 placed in your main game directory ( main.c )
*/   
// ----------------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------------
STRING* MS_Song1      = "song1.mp3";                   // place mp3's in project's main folder
STRING* MS_Song2      = "song2.mp3";
//STRING* MS_Song3    = "song3.mp3";                   // and so on ...
// ----------------------------------------------------------------------------------------------
var _mm_music_on      =  1;                            // 0 = stop music
var _ms_song_newsong  =  1;                            // change this value to load new song nr X
var _ms_song_playing  =  0;                            // song which is playing right now
var _ms_song_handle   =  0;                            // handle to now playing song
var _ms_master_volume = 80;                            // master volume 4 song play
// ----------------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------------
void _init_music_system(){                             // global running music box function
   proc_mode          = PROC_GLOBAL; 	
   var _fade_to_sound = 0;
   var _volume        = 0;
   _ms_song_handle    = media_loop (MS_Song1, NULL, 0);
   while (1){
      if (!_mm_music_on)              { media_stop (_ms_song_handle); break; return; } // stop all
      if (_volume != _ms_master_volume) media_tune (_ms_song_handle, _ms_master_volume, NULL, 0);//changed vol?		
      if (_ms_song_playing != _ms_song_newsong && !_fade_to_sound){
         _fade_to_sound    = 1;
         _ms_song_playing  = _ms_song_newsong;
         while (_volume > 0){
            _volume -= time_step * 2;
            media_tune (_ms_song_handle, _volume, NULL, 0);
            wait (1);
         }
         media_stop (_ms_song_handle); 
         if (_ms_song_newsong == 1) _ms_song_handle = media_loop (MS_Song1, NULL, 0); 
         if (_ms_song_newsong == 2) _ms_song_handle = media_loop (MS_Song2, NULL, 0); 
       //if (_ms_song_newsong == 3) _ms_song_handle = media_loop (MS_Song3, NULL, 0); 	      
         while (_volume < _ms_master_volume){
            _volume += time_step * 2;
            media_tune (_ms_song_handle, _volume, NULL, 0);
            wait (1);
         }
         _fade_to_sound = 0;
      }		
      wait (1);
   }
}
// ----------------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------------
// end of this great contribution ... ifuwant give credits 2 rayp ... building a deathstar withit
// ----------------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------------

See manual
Quote:
media_play, media_tune, media_loop, media_stop
4 more Infos

Greets


Acknex umgibt uns...zwischen Dir, mir, dem Stein dort...
"Hey Griswold ... where u gonna put a tree that big ?"
1998 i married my loved wife ... Sheeva from Mortal Kombat, not Evil-Lyn as might have been expected
rayp.flags |= UNTOUCHABLE;
Re: A simple ( mp3 ) music system example script [Re: rayp] #439139
03/27/14 15:23
03/27/14 15:23
Joined: Feb 2010
Posts: 886
Random Offline
User
Random  Offline
User

Joined: Feb 2010
Posts: 886
Finally!
An exsample with all the functions!

Thanks!



Re: A simple ( mp3 ) music system example script [Re: Random] #439158
03/27/14 20:23
03/27/14 20:23
Joined: Jul 2008
Posts: 2,107
Germany
rayp Offline OP

X
rayp  Offline OP

X

Joined: Jul 2008
Posts: 2,107
Germany
Your welcome!


Acknex umgibt uns...zwischen Dir, mir, dem Stein dort...
"Hey Griswold ... where u gonna put a tree that big ?"
1998 i married my loved wife ... Sheeva from Mortal Kombat, not Evil-Lyn as might have been expected
rayp.flags |= UNTOUCHABLE;
Re: A simple ( mp3 ) music system example script [Re: rayp] #441024
05/09/14 17:33
05/09/14 17:33
Joined: Jul 2001
Posts: 4,801
netherlands
Realspawn Offline

Expert
Realspawn  Offline

Expert

Joined: Jul 2001
Posts: 4,801
netherlands
great contribution as always laugh


Find all my tutorials & Workshops at : www.rp-interactive.nl

Creativity starts in the brain
Re: A simple ( mp3 ) music system example script [Re: Realspawn] #441046
05/10/14 13:25
05/10/14 13:25
Joined: May 2010
Posts: 34
S
Scifi Offline
Newbie
Scifi  Offline
Newbie
S

Joined: May 2010
Posts: 34
Share my very simple music player I wrote a long time ago because I thought it could be useful if one wants a lightweight but fully-featured music player without having to rewrite it. grin

Just plug the code in your projects and run - no additional files or dependencies required. And you can write a GUI that makes use of the functions, for example, one GUI button that use mpNext(), which will cycle to the next song in the list.

mpLoad(STRING *scan_path, STRING *scan_ext) must first be called to determine which directory to scan and the file extension, for example
Code:
mpLoad( "./sound/music/", "*.mp3" );



Header :
Code:
TEXT *mpPool = { strings ( 1000 ); } // Maximum of 1000 songs
int mpCount = 0, mpRandomize = 1, mpSongs, mpPauseMark;
var mpHandle;

var MainMenuMusicHndl;
void mpLoad(STRING *, STRING *);
void mpUnload();
void mpPrev();
void mpNext();
void mpPause();
void mpResume();
void mpPlay(STRING *);



Code:
/*
--------------------------------------------------
void mpLoad(STRING *scan_path, STRING *scan_ext)

Desc:

Returns: -
--------------------------------------------------
*/
void mpLoad(STRING *scan_path, STRING *scan_ext) {

STRING *_scan_path = str_create(scan_path); // Prevent modification of the original string

mpSongs = txt_for_dir(mpPool, str_cat(_scan_path,scan_ext) );
while(proc_status(txt_for_dir)) wait(1);

str_remove(_scan_path);

}

/*
--------------------------------------------------
void mpPlay(STRING *songName)

Desc:

Returns: -
--------------------------------------------------
*/
void mpPlay(STRING *songName) {

if(media_playing(mpHandle)) media_stop(mpHandle);
if(mpCount > mpSongs - 1 || mpCount < 0) return;

str_cpy(_mpSongTemp,songName);
str_trunc(_mpSongTemp, str_len( 4 )-1 );
str_cpy(mpSongTemp,PATH_MUSIC);
str_cat(mpSongTemp,songName);

str_for_num(_mpCount, mpCount); // strcpy is unnecessary here

mpHandle = media_play(mpSongTemp,NULL,VOL_MUSIC);

while(media_playing(mpHandle)) wait(1);
mpNext();

}

/*
--------------------------------------------------
void mpNext()

Desc:

Returns: -
--------------------------------------------------
*/
void mpNext() {

if(event_type == EVENT_RELEASE) return;

if(mpCount < mpSongs) {

if(mpRandomize) mpCount = (int) random(mpSongs);
else mpCount += 1;
mpPlay( (mpPool.pstring)[mpCount] );

}

}

/*
--------------------------------------------------
void mpPrev()

Desc:

Returns: -
--------------------------------------------------
*/
void mpPrev() {

if(event_type == EVENT_RELEASE) return;

if(mpCount >= 0) {

if(mpRandomize) mpCount = (int) random(mpSongs);
else mpCount -= 1;
mpPlay( (mpPool.pstring)[mpCount] );

}

}

/*
--------------------------------------------------
void mpPause()

Desc:

Returns: -
--------------------------------------------------
*/
void mpPause() {

if(event_type == EVENT_RELEASE) return;

if(media_playing(mpHandle)) {

media_pause(mpHandle);
mpPauseMark = 1;

}

}

/*
--------------------------------------------------
void mpResume()

Desc:

Returns: -
--------------------------------------------------
*/
void mpResume() {

if(event_type == EVENT_RELEASE) return;

if(mpPauseMark) media_start(mpHandle);

}



Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

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