Flutter Engine
The Flutter Engine
third_party
skia
modules
audioplayer
SkAudioPlayer_sfml.cpp
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
8
#include "
include/core/SkData.h
"
9
#include "
modules/audioplayer/SkAudioPlayer.h
"
10
11
#include <SFML/Audio.hpp>
12
13
namespace
{
14
15
class
SFMLAudioPlayer final :
public
SkAudioPlayer
{
16
public
:
17
explicit
SFMLAudioPlayer(
sk_sp<SkData>
data
)
18
: fData(
std
::move(
data
))
19
{
20
fMusic.openFromMemory(fData->data(), fData->size());
21
}
22
23
private
:
24
double
onGetDuration
()
const override
{
25
return
static_cast<
double
>
(fMusic.getDuration().asSeconds());
26
}
27
28
double
onGetTime
()
const override
{
29
return
static_cast<
double
>
(fMusic.getPlayingOffset().asSeconds());
30
}
31
32
double
onSetTime
(
double
t)
override
{
33
fMusic.setPlayingOffset(sf::seconds(
static_cast<
float
>
(t)));
34
35
return
this->
onGetTime
();
36
}
37
38
State
onSetState
(
State
state
)
override
{
39
switch
(
state
) {
40
case
State::kPlaying
: fMusic.play();
break
;
41
case
State::kStopped
: fMusic.stop();
break
;
42
case
State::kPaused
: fMusic.pause();
break
;
43
}
44
45
return
state
;
46
}
47
48
float
onSetRate
(
float
r)
override
{
49
fMusic.setPitch(r);
50
return
r;
51
}
52
53
float
onSetVolume
(
float
v)
override
{
54
fMusic.setVolume(v * 100);
55
return
v;
56
}
57
58
const
sk_sp<SkData>
fData;
59
sf::Music fMusic;
60
};
61
62
}
// namespace
63
64
std::unique_ptr<SkAudioPlayer>
SkAudioPlayer::Make
(
sk_sp<SkData>
src
) {
65
auto
player = std::make_unique<SFMLAudioPlayer>(std::move(
src
));
66
67
return
player->duration() > 0 ? std::move(player) : nullptr;
68
}
SkAudioPlayer.h
SkData.h
SkAudioPlayer
Definition:
SkAudioPlayer.h:12
SkAudioPlayer::onSetTime
virtual double onSetTime(double)=0
SkAudioPlayer::State::kPaused
@ kPaused
SkAudioPlayer::State::kPlaying
@ kPlaying
SkAudioPlayer::State::kStopped
@ kStopped
SkAudioPlayer::Make
static std::unique_ptr< SkAudioPlayer > Make(sk_sp< SkData >)
Definition:
SkAudioPlayer_none.cpp:11
SkAudioPlayer::onGetDuration
virtual double onGetDuration() const =0
SkAudioPlayer::onGetTime
virtual double onGetTime() const =0
SkAudioPlayer::onSetVolume
virtual float onSetVolume(float)=0
SkAudioPlayer::onSetState
virtual State onSetState(State)=0
SkAudioPlayer::onSetRate
virtual float onSetRate(float)=0
SkAudioPlayer::state
State state() const
Definition:
SkAudioPlayer.h:32
sk_sp< SkData >
state
AtkStateType state
Definition:
fl_accessible_node.cc:10
mskp_parser.src
src
Definition:
mskp_parser.py:22
std
Definition:
ref_ptr.h:256
State
Definition:
SerialProcsTest.cpp:46
data
std::shared_ptr< const fml::Mapping > data
Definition:
texture_gles.cc:63
Generated on Sun Jun 23 2024 21:56:04 for Flutter Engine by
1.9.4