-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fix {{sound-position-slider}} modifier gestures
feat: add {{sound-position-progress}} modifier
- Loading branch information
Showing
12 changed files
with
360 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/** | ||
* This is the modifier used to transform an element into a progress bar, where it will take up the width equivalent to the sound's position | ||
* ```hbs | ||
<div {{sound-position-progress @identifier}}> | ||
</div> | ||
``` | ||
* | ||
@class {{sound-position-progress}} | ||
@type Modifier | ||
*/ | ||
|
||
import { action } from '@ember/object'; | ||
import { inject as service } from '@ember/service'; | ||
import Modifier from 'ember-modifier'; | ||
|
||
export default class SoundPositionProgressModifier extends Modifier { | ||
@service stereo; | ||
|
||
get url() { | ||
return this.args.positional[0] | ||
} | ||
|
||
get loadedSound() { | ||
return this.stereo.findSound(this.url); | ||
} | ||
|
||
@action onPositionChange() { | ||
this.element.style.width = `${(this.loadedSound.position / this.loadedSound.duration) * 100}%`; | ||
this.element.style.pointerEvents = 'none'; | ||
} | ||
|
||
didInstall() { | ||
this.element.setAttribute('data-sound-position-progress', true) | ||
} | ||
|
||
didReceiveArguments() { | ||
if (this.url) { | ||
this.stereo.soundProxy(this.url).afterLoad(sound => { | ||
sound.on('audio-position-changed', this.onPositionChange); | ||
}) | ||
} | ||
} | ||
|
||
willRemove() { | ||
try { | ||
if (this.loadedSound) { | ||
this.loadedSound.off('audio-position-changed', this.onPositionChange); | ||
} | ||
} catch (e) { /* geez, relax */ } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from 'ember-stereo/modifiers/sound-position-progress'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
tests/dummy/app/components/docs/custom-position-control.hbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
<div class='stereo-player'> | ||
<div class='stereo-player-main'> | ||
<div class='stereo-player-controls'> | ||
<button | ||
{{on 'click' (rewind-sound @identifier increment=5000)}} | ||
disabled={{not (sound-is-rewindable @identifier)}} | ||
type='button' | ||
class='stereo-button' | ||
> | ||
{{svg-jar | ||
'skip-backward-outline' | ||
height=20 | ||
width=30 | ||
title='Skip Backward' | ||
}} | ||
</button> | ||
|
||
<button | ||
{{on 'click' (toggle-play-sound @identifier)}} | ||
type='button' | ||
class='stereo-button' | ||
> | ||
{{#if (sound-is-playing @identifier)}} | ||
{{svg-jar 'pause-outline' height=20 width=30 title='Pause'}} | ||
{{else if (sound-is-loading @identifier)}} | ||
{{svg-jar | ||
'loading-outline' | ||
height=20 | ||
width=30 | ||
title='Loading' | ||
class='animate-spin' | ||
}} | ||
{{else if (sound-is-loaded @identifier)}} | ||
{{svg-jar 'resume-outline' height=20 width=30 title='Pause'}} | ||
{{else}} | ||
{{svg-jar 'play-outline' height=20 width=30 title='Play'}} | ||
{{/if}} | ||
</button> | ||
|
||
<button | ||
{{on 'click' (fastforward-sound @identifier increment=5000)}} | ||
disabled={{not (sound-is-fastforwardable @identifier)}} | ||
type='button' | ||
class='stereo-button' | ||
> | ||
{{svg-jar | ||
'skip-forward-outline' | ||
height=20 | ||
width=30 | ||
title='Skip Forward' | ||
}} | ||
</button> | ||
</div> | ||
|
||
<div class='stereo-player-position'> | ||
{{sound-position @identifier format='time'}} | ||
{{#if (sound-is-seekable @identifier)}} | ||
{{! template-lint-disable require-input-label }} | ||
{{! BEGIN-SNIPPET position-modifiers.hbs }} | ||
<div {{sound-position-slider @identifier}} class="stereo-player-position-slider" > | ||
<div {{sound-position-progress @identifier}} class="stereo-player-position-progress" ></div> | ||
</div> | ||
{{! END-SNIPPET }} | ||
{{else}} | ||
<div | ||
class='{{if | ||
(sound-is-playing @identifier) | ||
'from-accent-0 to-accent-2 bg-gradient-to-r animate-gradient-x animated' | ||
'bg-on-surface-3' | ||
}} | ||
w-full h-2 rounded-md inset-1 shadow-inset' | ||
> | ||
</div> | ||
{{/if}} | ||
{{sound-duration @identifier format='time'}} | ||
</div> | ||
|
||
<div class='stereo-player-volume'> | ||
<Input | ||
{{stereo-volume}} | ||
id='stereo-volume' | ||
@type='range' | ||
class='flex-auto flex-shrink w-16 lg:w-1/6' | ||
/> | ||
<label for='stereo-volume' class='stereo-volume'> | ||
<button type='button' {{on 'click' (toggle-stereo-mute)}}> | ||
{{#if (gt (stereo-volume) 0)}} | ||
{{svg-jar 'volume-low-outline' height=20 width=30}} | ||
{{else}} | ||
{{svg-jar 'volume-mute-outline' height=20 width=30}} | ||
{{/if}} | ||
</button> | ||
</label> | ||
</div> | ||
</div> | ||
|
||
{{#if (sound-is-errored @identifier)}} | ||
<div class='stereo-player-errors'> | ||
{{sound-error-details @identifier}} | ||
</div> | ||
{{/if}} | ||
</div> | ||
|
||
|
||
<DocsDemo as |demo|> | ||
{{demo.snippet 'position-modifiers.hbs'}} | ||
</DocsDemo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
{{docs/custom-position-control identifier="/sounds/works-just-like-a-vcr.mp3"}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
tests/integration/modifiers/sound-position-progress-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { module, test } from 'qunit'; | ||
import { setupRenderingTest } from 'ember-qunit'; | ||
import { render } from '@ember/test-helpers'; | ||
import { hbs } from 'ember-cli-htmlbars'; | ||
|
||
module('Integration | Modifier | sound-position-progress', function (hooks) { | ||
setupRenderingTest(hooks); | ||
|
||
test('it renders', async function (assert) { | ||
await render(hbs`<div {{sound-position-progress}}></div>`); | ||
|
||
assert.ok(true); | ||
}); | ||
}); |
Oops, something went wrong.