c9c4e2e9ef
Relocate under modules/audioplayer and package as a standalone component. Change-Id: If9dc72bb0abe170049a514c9931186703a3c138a Reviewed-on: https://skia-review.googlesource.com/c/skia/+/310058 Commit-Queue: Florin Malita <fmalita@google.com> Reviewed-by: Mike Reed <reed@google.com>
58 lines
1.2 KiB
C++
58 lines
1.2 KiB
C++
/*
|
|
* Copyright 2020 Google Inc.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
* found in the LICENSE file.
|
|
*/
|
|
|
|
#include "modules/audioplayer/SkAudioPlayer.h"
|
|
#include <algorithm>
|
|
#include <cmath>
|
|
|
|
SkAudioPlayer::~SkAudioPlayer() {}
|
|
|
|
double SkAudioPlayer::setTime(double t) {
|
|
t = std::min(std::max(t, 0.0), this->duration());
|
|
if (!std::isfinite(t)) {
|
|
t = this->time();
|
|
}
|
|
if (t != this->time()) {
|
|
t = this->onSetTime(t);
|
|
}
|
|
return t;
|
|
}
|
|
|
|
double SkAudioPlayer::setNormalizedTime(double t) {
|
|
this->setTime(t * this->duration());
|
|
return this->normalizedTime();
|
|
}
|
|
|
|
SkAudioPlayer::State SkAudioPlayer::setState(State s) {
|
|
if (s != fState) {
|
|
fState = this->onSetState(s);
|
|
}
|
|
return fState;
|
|
}
|
|
|
|
float SkAudioPlayer::setRate(float r) {
|
|
r = std::min(std::max(r, 0.f), 1.f);
|
|
if (!std::isfinite(r)) {
|
|
r = fRate;
|
|
}
|
|
if (r != fRate) {
|
|
fRate = this->onSetRate(r);
|
|
}
|
|
return fRate;
|
|
}
|
|
|
|
float SkAudioPlayer::setVolume(float v) {
|
|
v = std::min(std::max(v, 0.f), 1.f);
|
|
if (!std::isfinite(v)) {
|
|
v = fVolume;
|
|
}
|
|
if (v != fVolume) {
|
|
fVolume = this->onSetVolume(v);
|
|
}
|
|
return fVolume;
|
|
}
|