Example #1
0
void pause_play(buffer *buf, playlist *pl)
{
    static char file[PATH_MAX] = "";
    static signed long seek = 0;
    
    if (buf == NULL && pl == NULL) /* reset */
    {
        strcpy(file, "");
        seek = 0;
        return;
    }
    
    /* pause */
    if (strlen(file) == 0)
    {
        status = MPG321_PAUSED;
        strncpy(file, buf->filename, PATH_MAX);
        file[PATH_MAX-1]='\0';
        clear_remote_file(pl);
        seek = current_frame;
        printf("@P 1\n");
    }
    
    /* unpause */
    else
    {
        status = MPG321_SEEKING;
        play_remote_file(pl, file);
        file[0] = '\0';
        options.seek = seek;
        current_frame = 0;
        printf("@P 2\n");
    }
}
Example #2
0
void pause_play(buffer *buf, playlist *pl)
{
    static char file[PATH_MAX] = "";
    static signed long seek = 0;
    
    if (buf == NULL && pl == NULL) /* reset */
    {
        strcpy(file, "");
        seek = 0;
        return;
    }
    
    /* pause */
    if (strlen(file) == 0)
    {
        status = MPG321_PAUSED;
        strncpy(file, buf->filename, PATH_MAX);
        file[PATH_MAX-1]='\0';
        clear_remote_file(pl);
	if(options.opt & MPG321_ENABLE_BUFFER)
		seek = Decoded_Frames->total_played_frames;
	else
		seek = current_frame;
	if(options.opt & MPG321_ENABLE_BUFFER) Decoded_Frames->stop_playing_file = 1;
        printf("@P 1\n");
    }
    
    /* unpause */
    else
    {
        status = MPG321_SEEKING;
        play_remote_file(pl, file);
        file[0] = '\0';
        options.seek = seek;
	//fprintf(stderr,"options.seek = %d\n",seek);
        current_frame = 0;
	mad_decoder_position = 0;
        printf("@P 2\n");
    }
}
static
enum mad_flow remote_parse_input(buffer *buf, playlist *pl)
{
    char input[PATH_MAX + 5]; /* for filename as well as input and space */
    char new_remote_input_buf[PATH_MAX + 5];
    char *arg;
    int numread;
    int alreadyread;
    int linelen;

    fd_set fd;
    struct timeval tv = { 0, 0 };
    FD_ZERO(&fd);
    FD_SET(0,&fd);

    alreadyread = strlen (remote_input_buf);

    if (select (1, &fd, NULL, NULL, &tv))
    {
      if (!(numread = read(0, remote_input_buf + alreadyread, (sizeof(input)-1)-alreadyread)) > 0)
      {
        numread = 0;
        /* fprintf(stderr, "remote_parse_input() called with no input queued!");
        exit(1);
        This never happens.. (read blocks) */
      }
    } else {
      numread = 0;
    }

    remote_input_buf[numread+alreadyread] = '\0';
    
    if ((arg = strchr(remote_input_buf, '\n')))
    {
        *(arg) = '\0';
    }

    linelen = strlen (remote_input_buf);

    strcpy (input, remote_input_buf);
    /* input[linelen] = '\0'; */
    strcpy (new_remote_input_buf, remote_input_buf + linelen + 1);
    /* don't copy the \0... */
    strcpy (remote_input_buf, new_remote_input_buf);

    trim_whitespace(input); /* Trims on left and right side only */

    if (strlen(input) == 0)
        return 0;

    arg = strchr(input, ' ');

    if (arg)
    {
        *(arg++) = '\0';
        arg = strdup(arg);
        trim_whitespace(arg);
    }

    if (strcasecmp(input, "L") == 0 || strcasecmp(input, "LOAD") == 0)
    {
        if(arg)
        {
            status = MPG321_PLAYING;
            play_remote_file(pl, arg);
            current_frame = 0;
            options.seek = 0;
            pause_play(NULL, NULL); /* reset pause data */
            goto stop;
        }

        else
        {
            /* this works because if there's no argument, input is just
              'l' or 'load' */
            printf("@E Missing argument to '%s'\n",input);
            return 0;
        }
    }

    else if (strcasecmp(input, "J") == 0 || strcasecmp(input, "JUMP") == 0)
    {
        if (status == MPG321_PLAYING && arg)
        {
            /* relative seek */
            if (arg[0] == '-' || arg[0] == '+')
            {
                signed long toMove = atol(arg);
            
                /* on forward seeks we don't need to stop decoding */
                enum mad_flow toDo = move(buf, toMove);
                
                if (arg) 
                    free(arg);

                return toDo;
            }
            
            /* absolute seek */
            else
            {
                long toSeek = atol(arg);
                
                seek(buf, toSeek);
                goto stop;
            }
        }
        
        else
        {
            /* mpg123 does no error checking, so we should emulate them */
        }                        
    }
    
    else if (strcasecmp(input, "S") == 0 || strcasecmp(input, "STOP") == 0)
    {
        if (status != MPG321_STOPPED)
        {
            status = MPG321_STOPPED;
            clear_remote_file(pl);
            current_frame = 0;
            pause_play(NULL, NULL); /* reset pause data */
            printf("@P 0\n");
        }
        
        goto stop;
    }
    
    else if (strcasecmp(input, "Q") == 0 || strcasecmp(input, "QUIT") == 0)
    {
        quit_now = 1;
        goto stop;
    }
    
    else if (strcasecmp(input, "P") == 0 || strcasecmp(input, "PAUSE") == 0)
    {
        if (status == MPG321_PLAYING || status == MPG321_PAUSED)
        {
            pause_play(buf, pl);
        }

        goto stop;
    }

    else 
    {
        fprintf(stderr, "@E Unknown command '%s'\n", input);

    }

    if (arg) 
        free(arg);
    return 0;

stop:
    if (arg)
        free(arg);
    return MAD_FLOW_STOP;    
}