player: add "pause" command, small fixes

- position cannot get negative, so use unsigned

- be sure that the read line is null-terminated (for strlen)

- clear buffers to avoid playing old data
This commit is contained in:
Peter Wu 2012-07-12 23:32:36 +02:00
parent f2d142c9c7
commit 25b1d31b00

View file

@ -150,12 +150,13 @@ seekDone:
if (fgets(line, sizeof(line), stdin) == NULL){
return false;
}
line[sizeof(line) - 1] = 0;// in case stream is not null-terminated...
line_len = strlen(line);
if (line[line_len - 1] == '\n'){
line[--line_len] = 0;
}
{
int position = INT_MAX;// special value that says "invalid"
unsigned int position = INT_MAX;// special value that says "invalid"
if (!strncmp("seek ", line, sizeof("seek ") - 1)){
position = atoi(line + sizeof("seek ") - 1);
}
@ -165,17 +166,22 @@ seekDone:
}
if (position != INT_MAX){
File::seek(position);
inBuffer.clear();//clear buffered data from file
return true;
}
}
if (!strncmp("byteseek ", line, sizeof("byteseek " - 1))){
std::streampos byte = atoi(line + sizeof("byteseek "));
fileSrc.seekg(byte);//if EOF, then it's the client's fault, ignore it.
inBuffer.clear();//clear buffered data from file
return true;
}
if (!strcmp("play", line)){
playing = true;
}
if (!strcmp("pause", line)){
playing = false;
}
return false;
}