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 "modules/audioplayer/SkAudioPlayer.h" 9 #include <algorithm> 10 #include <cmath> 11 ~SkAudioPlayer()12SkAudioPlayer::~SkAudioPlayer() {} 13 setTime(double t)14double SkAudioPlayer::setTime(double t) { 15 t = std::min(std::max(t, 0.0), this->duration()); 16 if (!std::isfinite(t)) { 17 t = this->time(); 18 } 19 if (t != this->time()) { 20 t = this->onSetTime(t); 21 } 22 return t; 23 } 24 setNormalizedTime(double t)25double SkAudioPlayer::setNormalizedTime(double t) { 26 this->setTime(t * this->duration()); 27 return this->normalizedTime(); 28 } 29 setState(State s)30SkAudioPlayer::State SkAudioPlayer::setState(State s) { 31 if (s != fState) { 32 fState = this->onSetState(s); 33 } 34 return fState; 35 } 36 setRate(float r)37float SkAudioPlayer::setRate(float r) { 38 r = std::min(std::max(r, 0.f), 1.f); 39 if (!std::isfinite(r)) { 40 r = fRate; 41 } 42 if (r != fRate) { 43 fRate = this->onSetRate(r); 44 } 45 return fRate; 46 } 47 setVolume(float v)48float SkAudioPlayer::setVolume(float v) { 49 v = std::min(std::max(v, 0.f), 1.f); 50 if (!std::isfinite(v)) { 51 v = fVolume; 52 } 53 if (v != fVolume) { 54 fVolume = this->onSetVolume(v); 55 } 56 return fVolume; 57 } 58