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:
parent
f2d142c9c7
commit
25b1d31b00
1 changed files with 7 additions and 1 deletions
|
@ -150,12 +150,13 @@ seekDone:
|
||||||
if (fgets(line, sizeof(line), stdin) == NULL){
|
if (fgets(line, sizeof(line), stdin) == NULL){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
line[sizeof(line) - 1] = 0;// in case stream is not null-terminated...
|
||||||
line_len = strlen(line);
|
line_len = strlen(line);
|
||||||
if (line[line_len - 1] == '\n'){
|
if (line[line_len - 1] == '\n'){
|
||||||
line[--line_len] = 0;
|
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)){
|
if (!strncmp("seek ", line, sizeof("seek ") - 1)){
|
||||||
position = atoi(line + sizeof("seek ") - 1);
|
position = atoi(line + sizeof("seek ") - 1);
|
||||||
}
|
}
|
||||||
|
@ -165,17 +166,22 @@ seekDone:
|
||||||
}
|
}
|
||||||
if (position != INT_MAX){
|
if (position != INT_MAX){
|
||||||
File::seek(position);
|
File::seek(position);
|
||||||
|
inBuffer.clear();//clear buffered data from file
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!strncmp("byteseek ", line, sizeof("byteseek " - 1))){
|
if (!strncmp("byteseek ", line, sizeof("byteseek " - 1))){
|
||||||
std::streampos byte = atoi(line + sizeof("byteseek "));
|
std::streampos byte = atoi(line + sizeof("byteseek "));
|
||||||
fileSrc.seekg(byte);//if EOF, then it's the client's fault, ignore it.
|
fileSrc.seekg(byte);//if EOF, then it's the client's fault, ignore it.
|
||||||
|
inBuffer.clear();//clear buffered data from file
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (!strcmp("play", line)){
|
if (!strcmp("play", line)){
|
||||||
playing = true;
|
playing = true;
|
||||||
}
|
}
|
||||||
|
if (!strcmp("pause", line)){
|
||||||
|
playing = false;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue