Flutter Engine
The Flutter Engine
third_party
skia
tools
viewer
AudioSlide.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/SkCanvas.h
"
9
#include "
include/core/SkData.h
"
10
#include "
modules/audioplayer/SkAudioPlayer.h
"
11
#include "
src/base/SkUtils.h
"
12
#include "
tools/Resources.h
"
13
#include "
tools/viewer/ClickHandlerSlide.h
"
14
15
class
AudioSlide
:
public
ClickHandlerSlide
{
16
std::unique_ptr<SkAudioPlayer> fPlayer;
17
SkRect
fBar;
18
19
public
:
20
AudioSlide
() {
fName
=
"Audio"
; }
21
22
void
load
(
SkScalar
w
,
SkScalar
h
)
override
{
23
auto
data
=
SkData::MakeFromFileName
(
"/Users/reed/skia/mp3/scott-joplin-peacherine-rag.mp3"
);
24
if
(
data
) {
25
fPlayer =
SkAudioPlayer::Make
(
data
);
26
27
SkDebugf
(
"make: dur:%g time%g state:%d"
,
28
fPlayer->duration(),
29
fPlayer->time(),
30
(
int
)fPlayer->state());
31
}
32
33
fBar = { 10, 10, 510, 30 };
34
}
35
36
void
draw
(
SkCanvas
* canvas)
override
{
37
if
(!fPlayer) {
38
return
;
39
}
40
41
SkPaint
p
;
42
p
.setColor(0xFFCCCCCC);
43
canvas->
drawRect
(fBar,
p
);
44
45
p
.setColor(fPlayer->isPlaying() ?
SK_ColorBLUE
: 0xFF8888FF);
46
SkRect
r = fBar;
47
r.
fRight
= r.
fLeft
+ (
float
)fPlayer->normalizedTime() * r.
width
();
48
canvas->
drawRect
(r,
p
);
49
}
50
51
bool
onChar
(
SkUnichar
c)
override
{
52
if
(c ==
' '
) {
53
switch
(fPlayer->state()) {
54
case
SkAudioPlayer::State::kPlaying
: fPlayer->pause();
break
;
55
case
SkAudioPlayer::State::kPaused
: fPlayer->play();
break
;
56
case
SkAudioPlayer::State::kStopped
: fPlayer->play();
break
;
57
}
58
return
true
;
59
}
60
return
this->
ClickHandlerSlide::onChar
(c);
61
}
62
63
Click
*
onFindClickHandler
(
SkScalar
x
,
SkScalar
y
,
skui::ModifierKey
)
override
{
64
if
(fPlayer && fBar.
contains
(
x
,
y
)) {
65
bool
wasPlaying = fPlayer->isPlaying();
66
if
(wasPlaying) {
67
fPlayer->pause();
68
}
69
return
new
Click
([
this
, wasPlaying](
Click
* click) {
70
if
(fBar.
contains
(click->
fCurr
.
fX
, click->
fCurr
.
fY
)) {
71
fPlayer->setNormalizedTime((click->fCurr.fX - fBar.fLeft) / fBar.width());
72
}
73
74
if
(click->
fState
==
skui::InputState::kUp
) {
75
if (wasPlaying) {
76
fPlayer->play();
77
}
78
}
79
return
true
;
80
});
81
}
82
return
nullptr
;
83
}
84
85
bool
onClick
(
ClickHandlerSlide::Click
*)
override
{
return
false
; }
86
87
bool
animate
(
double
/*nanos*/
)
override
{
88
return
true
;
89
}
90
91
};
92
93
DEF_SLIDE
(
return
new
AudioSlide
; )
ClickHandlerSlide.h
Resources.h
SkAudioPlayer.h
SkCanvas.h
SK_ColorBLUE
constexpr SkColor SK_ColorBLUE
Definition:
SkColor.h:135
SkData.h
SkDebugf
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
SkUnichar
int32_t SkUnichar
Definition:
SkTypes.h:175
SkUtils.h
DEF_SLIDE
#define DEF_SLIDE(code)
Definition:
Slide.h:25
AudioSlide
Definition:
AudioSlide.cpp:15
AudioSlide::onChar
bool onChar(SkUnichar c) override
Definition:
AudioSlide.cpp:51
AudioSlide::onFindClickHandler
Click * onFindClickHandler(SkScalar x, SkScalar y, skui::ModifierKey) override
Definition:
AudioSlide.cpp:63
AudioSlide::draw
void draw(SkCanvas *canvas) override
Definition:
AudioSlide.cpp:36
AudioSlide::AudioSlide
AudioSlide()
Definition:
AudioSlide.cpp:20
AudioSlide::load
void load(SkScalar w, SkScalar h) override
Definition:
AudioSlide.cpp:22
AudioSlide::animate
bool animate(double) override
Definition:
AudioSlide.cpp:87
AudioSlide::onClick
bool onClick(ClickHandlerSlide::Click *) override
Definition:
AudioSlide.cpp:85
ClickHandlerSlide::Click
Definition:
ClickHandlerSlide.h:25
ClickHandlerSlide::Click::fState
skui::InputState fState
Definition:
ClickHandlerSlide.h:35
ClickHandlerSlide::Click::fCurr
SkPoint fCurr
Definition:
ClickHandlerSlide.h:33
ClickHandlerSlide
Definition:
ClickHandlerSlide.h:22
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
SkCanvas
Definition:
SkCanvas.h:106
SkCanvas::drawRect
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition:
SkCanvas.cpp:1673
SkData::MakeFromFileName
static sk_sp< SkData > MakeFromFileName(const char path[])
Definition:
SkData.cpp:148
SkPaint
Definition:
SkPaint.h:44
Slide::onChar
virtual bool onChar(SkUnichar c)
Definition:
Slide.h:44
Slide::fName
SkString fName
Definition:
Slide.h:54
SkScalar
float SkScalar
Definition:
extension.cpp:12
if
if(end==-1)
Definition:
fl_accessible_text_field.cc:42
y
double y
Definition:
mouse-input-test.cc:83
x
double x
Definition:
mouse-input-test.cc:82
dart_profiler_symbols.p
p
Definition:
dart_profiler_symbols.py:55
skui::InputState::kUp
@ kUp
skui::ModifierKey
ModifierKey
Definition:
ModifierKey.h:9
tools.skpbench.skpbench.float
float
Definition:
skpbench.py:42
w
SkScalar w
Definition:
pictureshadertile.cpp:30
h
SkScalar h
Definition:
pictureshadertile.cpp:30
SkPoint::fX
float fX
x-axis value
Definition:
SkPoint_impl.h:164
SkPoint::fY
float fY
y-axis value
Definition:
SkPoint_impl.h:165
SkRect
Definition:
extension.cpp:13
SkRect::fLeft
SkScalar fLeft
smaller x-axis bounds
Definition:
extension.cpp:14
SkRect::fRight
SkScalar fRight
larger x-axis bounds
Definition:
extension.cpp:16
SkRect::contains
bool contains(SkScalar x, SkScalar y) const
Definition:
extension.cpp:19
SkRect::width
constexpr float width() const
Definition:
SkRect.h:762
data
std::shared_ptr< const fml::Mapping > data
Definition:
texture_gles.cc:63
Generated on Sun Jun 23 2024 21:56:51 for Flutter Engine by
1.9.4