Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
logging-scratch-gui
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
David Goessmann
logging-scratch-gui
Commits
022f60ed
Unverified
Commit
022f60ed
authored
6 years ago
by
Michael "Z" Goddard
Browse files
Options
Downloads
Patches
Plain Diff
use new SoundPlayer in SoundLibrary
- Stopping sounds fades them out avoiding potential audio clipping
parent
45ebe271
Branches
Branches containing commit
Tags
0.1.0-prerelease.20190417195037
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/containers/sound-library.jsx
+59
-7
59 additions, 7 deletions
src/containers/sound-library.jsx
with
59 additions
and
7 deletions
src/containers/sound-library.jsx
+
59
−
7
View file @
022f60ed
...
...
@@ -29,20 +29,63 @@ class SoundLibrary extends React.PureComponent {
'
handleItemMouseEnter
'
,
'
handleItemMouseLeave
'
]);
/**
* AudioEngine that will decode and play sounds for us.
* @type {AudioEngine}
*/
this
.
audioEngine
=
null
;
/**
* A promise for the sound queued to play as soon as it loads and
* decodes.
* @type {Promise<SoundPlayer>}
*/
this
.
playingSoundPromise
=
null
;
}
componentDidMount
()
{
this
.
audioEngine
=
new
AudioEngine
();
this
.
play
er
=
this
.
audioEngine
.
createPlayer
()
;
this
.
play
ingSoundPromise
=
null
;
}
componentWillUnmount
()
{
this
.
player
.
stopAllSounds
();
this
.
stopPlayingSound
();
}
stopPlayingSound
()
{
// Playback is queued, playing, or has played recently and finished
// normally.
if
(
this
.
playingSoundPromise
!==
null
)
{
// Queued playback began playing before this method.
if
(
this
.
playingSoundPromise
.
isPlaying
)
{
// Fetch the player from the promise and stop playback soon.
this
.
playingSoundPromise
.
then
(
soundPlayer
=>
{
soundPlayer
.
stop
();
});
}
else
{
// Fetch the player from the promise and stop immediately. Since
// the sound is not playing yet, this callback will be called
// immediately after the sound starts playback. Stopping it
// immediately will have the effect of no sound being played.
this
.
playingSoundPromise
.
then
(
soundPlayer
=>
{
soundPlayer
.
stopImmediately
();
});
}
// No further work should be performed on this promise and its
// soundPlayer.
this
.
playingSoundPromise
=
null
;
}
}
handleItemMouseEnter
(
soundItem
)
{
const
md5ext
=
soundItem
.
_md5
;
const
idParts
=
md5ext
.
split
(
'
.
'
);
const
md5
=
idParts
[
0
];
const
vm
=
this
.
props
.
vm
;
vm
.
runtime
.
storage
.
load
(
vm
.
runtime
.
storage
.
AssetType
.
Sound
,
md5
)
// In case enter is called twice without a corresponding leave
// inbetween, stop the last playback before queueing a new sound.
this
.
stopPlayingSound
();
// Save the promise so code to stop the sound may queue the stop
// instruction after the play instruction.
this
.
playingSoundPromise
=
vm
.
runtime
.
storage
.
load
(
vm
.
runtime
.
storage
.
AssetType
.
Sound
,
md5
)
.
then
(
soundAsset
=>
{
const
sound
=
{
md5
:
md5ext
,
...
...
@@ -50,14 +93,23 @@ class SoundLibrary extends React.PureComponent {
format
:
soundItem
.
format
,
data
:
soundAsset
.
data
};
return
this
.
audioEngine
.
decodeSound
(
sound
);
return
this
.
audioEngine
.
decodeSound
Player
(
sound
);
})
.
then
(
soundId
=>
{
this
.
player
.
playSound
(
soundId
);
.
then
(
soundPlayer
=>
{
soundPlayer
.
connect
(
this
.
audioEngine
);
// Play the sound. Playing the sound will always come before a
// paired stop if the sound must stop early.
soundPlayer
.
play
();
// Set that the sound is playing. This affects the type of stop
// instruction given if the sound must stop early.
if
(
this
.
playingSoundPromise
!==
null
)
{
this
.
playingSoundPromise
.
isPlaying
=
true
;
}
return
soundPlayer
;
});
}
handleItemMouseLeave
()
{
this
.
player
.
stopAll
Sound
s
();
this
.
stopPlaying
Sound
();
}
handleItemSelected
(
soundItem
)
{
const
vmSound
=
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment