Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

⏪ [Story system layer] Audio icon disappears when story has background audio #37314

Merged
merged 10 commits into from
Jan 7, 2022
6 changes: 6 additions & 0 deletions extensions/amp-story/1.0/amp-story-store-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ export const Action = {
TOGGLE_SHARE_MENU: 'toggleShareMenu',
ADD_SHOPPING_DATA: 'addShoppingData',
TOGGLE_STORY_HAS_PLAYBACK_UI: 'toggleStoryHasPlaybackUi',
TOGGLE_STORY_HAS_BACKGROUND_AUDIO: 'toggleStoryHasBackgroundAudio',
TOGGLE_SYSTEM_UI_IS_VISIBLE: 'toggleSystemUiIsVisible',
TOGGLE_UI: 'toggleUi',
SET_GYROSCOPE_PERMISSION: 'setGyroscopePermission',
Expand Down Expand Up @@ -340,6 +341,11 @@ const actions = (state, action, data) => {
...state,
[StateProperty.STORY_HAS_PLAYBACK_UI_STATE]: !!data,
});
case Action.TOGGLE_STORY_HAS_BACKGROUND_AUDIO:
return /** @type {!State} */ ({
...state,
[StateProperty.STORY_HAS_BACKGROUND_AUDIO_STATE]: !!data,
});
// Mutes or unmutes the story media.
case Action.TOGGLE_MUTED:
return /** @type {!State} */ ({
Expand Down
14 changes: 14 additions & 0 deletions extensions/amp-story/1.0/amp-story.js
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,7 @@ export class AmpStory extends AMP.BaseElement {
* @private
*/
buildSystemLayer_(initialPageId) {
this.updateAudioIcon_();
this.updatePausedIcon_();
this.element.appendChild(this.systemLayer_.build(initialPageId));
}
Expand Down Expand Up @@ -2124,6 +2125,19 @@ export class AmpStory extends AMP.BaseElement {
this.mediaPool_.play(this.backgroundAudioEl_);
}

/**
* Update the store if the story has background audio.
* @private
*/
updateAudioIcon_() {
const storyHasBackgroundAudio =
this.element.hasAttribute('background-audio');
this.storeService_.dispatch(
Action.TOGGLE_STORY_HAS_BACKGROUND_AUDIO,
storyHasBackgroundAudio
);
}

/**
* Shows the play/pause icon if there is an element with playback on the story.
* @private
Expand Down
12 changes: 12 additions & 0 deletions extensions/amp-story/1.0/test/test-amp-story.js
Original file line number Diff line number Diff line change
Expand Up @@ -921,6 +921,18 @@ describes.realWin(
});
});

it('should update the STORY_HAS_BACKGROUND_AUDIO property if story has background audio', async () => {
await createStoryWithPages(2, ['cover', 'page-1']);
story.element.setAttribute('background-audio', 'audio.mp3');
await story.layoutCallback();

expect(
story.storeService_.get(
StateProperty.STORY_HAS_BACKGROUND_AUDIO_STATE
)
).to.be.true;
});

it('should remove the muted attribute on unmuted state change', async () => {
await createStoryWithPages(2, ['cover', 'page-1']);

Expand Down