Skip to content

Commit

Permalink
feat(cmdline): add percentage seek
Browse files Browse the repository at this point in the history
Signed-off-by: pingkai <pingkai010@gmail.com>
  • Loading branch information
pingkai authored and skufly committed Apr 13, 2020
1 parent fecf86a commit 8c5628f
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 1 deletion.
2 changes: 2 additions & 0 deletions cmdline/IEventReceiver.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class IEventReceiver {

virtual void onStepSeek(bool forward) = 0;

virtual void onPercentageSeek(int percent) = 0;

virtual void onChangeVolume(bool large) = 0;

virtual void onSetView(void *view) = 0;
Expand Down
3 changes: 3 additions & 0 deletions cmdline/NetWorkEventReceiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ void NetWorkEventReceiver::poll(bool &exit)
break;

default:
if (c >= '0' && c <= '9') {
mListener.onPercentageSeek((c - '0') * 10);
}
break;
}
}
Expand Down
5 changes: 4 additions & 1 deletion cmdline/SDLEventReceiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ void SDLEventReceiver::poll(bool &exit) {
break;

default:
AF_LOGW("unknown key %c", event.key.keysym.sym);
if (event.key.keysym.sym >= SDLK_0 && event.key.keysym.sym <= SDLK_9) {
mListener.onPercentageSeek((event.key.keysym.sym - SDLK_0) * 10);
} else
AF_LOGW("unknown key %c", event.key.keysym.sym);
break;
}
break;
Expand Down
4 changes: 4 additions & 0 deletions cmdline/cicadaEventListener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ void cicadaEventListener::onStepSeek(bool forward)

mediaPlayer->SeekTo(mediaPlayer->GetCurrentPosition() + time, SEEK_MODE_INACCURATE);
}
void cicadaEventListener::onPercentageSeek(int percent)
{
mediaPlayer->SeekTo(mediaPlayer->GetDuration() / 100 * percent, SEEK_MODE_INACCURATE);
}

void cicadaEventListener::onChangeVolume(bool large)
{
Expand Down
2 changes: 2 additions & 0 deletions cmdline/cicadaEventListener.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ class cicadaEventListener : public IEventReceiver::Listener {

void onStepSeek(bool forward) override;

void onPercentageSeek(int percent) override;

void onChangeVolume(bool large) override;

void onSetView(void *view) override;
Expand Down

0 comments on commit 8c5628f

Please sign in to comment.