playmus.c
changeset 75 6024df94730b
parent 47 103ac6380537
child 83 c95d43cc6d38
     1.1 --- a/playmus.c	Mon Dec 18 03:08:03 2000 +0000
     1.2 +++ b/playmus.c	Tue Jan 02 21:48:29 2001 +0000
     1.3 @@ -36,6 +36,7 @@
     1.4  
     1.5  static int audio_open = 0;
     1.6  static Mix_Music *music = NULL;
     1.7 +static int next_track = 0;
     1.8  
     1.9  void CleanUp(void)
    1.10  {
    1.11 @@ -81,6 +82,15 @@
    1.12  		   Mix_PausedMusic() ? "yes" : "no");
    1.13  }
    1.14  
    1.15 +void IntHandler(int sig)
    1.16 +{
    1.17 +	switch (sig) {
    1.18 +	        case SIGINT:
    1.19 +			next_track++;
    1.20 +			break;
    1.21 +	}
    1.22 +}
    1.23 +
    1.24  main(int argc, char *argv[])
    1.25  {
    1.26  	int audio_rate;
    1.27 @@ -134,7 +144,7 @@
    1.28  		exit(255);
    1.29  	}
    1.30  	atexit(CleanUp);
    1.31 -	signal(SIGINT, exit);
    1.32 +	signal(SIGINT, IntHandler);
    1.33  	signal(SIGTERM, exit);
    1.34  
    1.35  	/* Open the audio device */
    1.36 @@ -153,21 +163,33 @@
    1.37  	/* Set the external music player, if any */
    1.38  	Mix_SetMusicCMD(getenv("MUSIC_CMD"));
    1.39  
    1.40 -	/* Load the requested music file */
    1.41 -	music = Mix_LoadMUS(argv[i]);
    1.42 -	if ( music == NULL ) {
    1.43 -		fprintf(stderr, "Couldn't load %s: %s\n",
    1.44 -						argv[i], SDL_GetError());
    1.45 -		exit(2);
    1.46 -	}
    1.47 +	while (argv[i]) {
    1.48 +		next_track = 0;
    1.49 +		
    1.50 +		/* Load the requested music file */
    1.51 +		music = Mix_LoadMUS(argv[i]);
    1.52 +		if ( music == NULL ) {
    1.53 +			fprintf(stderr, "Couldn't load %s: %s\n",
    1.54 +				argv[i], SDL_GetError());
    1.55 +			exit(2);
    1.56 +		}
    1.57 +		
    1.58 +		/* Play and then exit */
    1.59 +		printf("Playing %s\n", argv[i]);
    1.60 +		Mix_FadeInMusic(music,looping,2000);
    1.61 +		while ( !next_track && Mix_PlayingMusic() || Mix_PausedMusic() ) {
    1.62 +			if(interactive)
    1.63 +				Menu();
    1.64 +			else
    1.65 +				SDL_Delay(100);
    1.66 +		}
    1.67 +		Mix_FreeMusic(music);
    1.68  
    1.69 -	/* Play and then exit */
    1.70 -	Mix_FadeInMusic(music,looping,2000);
    1.71 -	while ( Mix_PlayingMusic() || Mix_PausedMusic() ) {
    1.72 -		if(interactive)
    1.73 -			Menu();
    1.74 -		else
    1.75 -			SDL_Delay(100);
    1.76 +		/* If the user presses Ctrl-C more than once, exit. */
    1.77 +		SDL_Delay(500);
    1.78 +		if ( next_track > 1 ) break;
    1.79 +		
    1.80 +		i++;
    1.81  	}
    1.82  	exit(0);
    1.83  }