Flutter Engine
The Flutter Engine
SkAudioPlayer.h
Go to the documentation of this file.
1/*
2 * Copyright 2020 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7#pragma once
8
10#include <memory>
11
13public:
14 virtual ~SkAudioPlayer();
15
16 // Returns null on failure (possibly unknown format?)
17 static std::unique_ptr<SkAudioPlayer> Make(sk_sp<SkData>);
18
19 // in seconds
20 double duration() const { return this->onGetDuration(); }
21 double time() const { return this->onGetTime(); } // 0...duration()
22 double setTime(double); // returns actual time
23
24 double normalizedTime() const { return this->time() / this->duration(); }
25 double setNormalizedTime(double t);
26
27 enum class State {
28 kPlaying,
29 kStopped,
30 kPaused,
31 };
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)
35
36 State setState(State); // returns actual State
37 float setRate(float); // returns actual rate
38 float setVolume(float); // returns actual volume
39
40 void play() { this->setState(State::kPlaying); }
41 void pause() { this->setState(State::kPaused); }
42 void stop() { this->setState(State::kStopped); }
43
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; }
47
48protected:
49 SkAudioPlayer() {} // only called by subclasses
50
51 virtual double onGetDuration() const = 0;
52 virtual double onGetTime() const = 0;
53 virtual double onSetTime(double) = 0;
54
55 virtual State onSetState(State) = 0;
56 virtual float onSetRate(float) = 0;
57 virtual float onSetVolume(float) = 0;
58
59private:
60 State fState = State::kStopped;
61 float fRate = 1.0f;
62 float fVolume = 1.0f;
63};
#define SK_API
Definition: SkAPI.h:35
virtual double onSetTime(double)=0
virtual double onGetDuration() const =0
double time() const
Definition: SkAudioPlayer.h:21
double normalizedTime() const
Definition: SkAudioPlayer.h:24
bool isPlaying() const
Definition: SkAudioPlayer.h:44
float rate() const
Definition: SkAudioPlayer.h:34
double duration() const
Definition: SkAudioPlayer.h:20
virtual double onGetTime() const =0
virtual float onSetVolume(float)=0
bool isPaused() const
Definition: SkAudioPlayer.h:45
virtual State onSetState(State)=0
virtual float onSetRate(float)=0
bool isStopped() const
Definition: SkAudioPlayer.h:46
float volume() const
Definition: SkAudioPlayer.h:33
State state() const
Definition: SkAudioPlayer.h:32
double duration
Definition: examples.cpp:30
AtkStateType state
SK_API sk_sp< SkDocument > Make(SkWStream *dst, const SkSerialProcs *=nullptr, std::function< void(const SkPicture *)> onEndPage=nullptr)
static double time(int loops, Benchmark *bench, Target *target)
Definition: nanobench.cpp:394