2 * Copyright 2020 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
9 #include "include/core/SkData.h"
12 class SK_API SkAudioPlayer {
14 virtual ~SkAudioPlayer();
16 // Returns null on failure (possibly unknown format?)
17 static std::unique_ptr<SkAudioPlayer> Make(sk_sp<SkData>);
20 double duration() const { return this->onGetDuration(); }
21 double time() const { return this->onGetTime(); } // 0...duration()
22 double setTime(double); // returns actual time
24 double normalizedTime() const { return this->time() / this->duration(); }
25 double setNormalizedTime(double t);
32 State state() const { return fState; }
33 float volume() const { return fVolume; } // 0...1
34 float rate() const { return fRate; } // multiplier (e.g. 1.0 is default)
36 State setState(State); // returns actual State
37 float setRate(float); // returns actual rate
38 float setVolume(float); // returns actual volume
40 void play() { this->setState(State::kPlaying); }
41 void pause() { this->setState(State::kPaused); }
42 void stop() { this->setState(State::kStopped); }
44 bool isPlaying() const { return this->state() == State::kPlaying; }
45 bool isPaused() const { return this->state() == State::kPaused; }
46 bool isStopped() const { return this->state() == State::kStopped; }
49 SkAudioPlayer() {} // only called by subclasses
51 virtual double onGetDuration() const = 0;
52 virtual double onGetTime() const = 0;
53 virtual double onSetTime(double) = 0;
55 virtual State onSetState(State) = 0;
56 virtual float onSetRate(float) = 0;
57 virtual float onSetVolume(float) = 0;
60 State fState = State::kStopped;