diff --git a/dotcom-rendering/src/components/AppsAudioPlayButton.stories.tsx b/dotcom-rendering/src/components/AudioPlayer/AppsAudioPlayButton.stories.tsx similarity index 100% rename from dotcom-rendering/src/components/AppsAudioPlayButton.stories.tsx rename to dotcom-rendering/src/components/AudioPlayer/AppsAudioPlayButton.stories.tsx diff --git a/dotcom-rendering/src/components/AppsAudioPlayButton.tsx b/dotcom-rendering/src/components/AudioPlayer/AppsAudioPlayButton.tsx similarity index 83% rename from dotcom-rendering/src/components/AppsAudioPlayButton.tsx rename to dotcom-rendering/src/components/AudioPlayer/AppsAudioPlayButton.tsx index 8a9bd63e9a6..7cd48b126d1 100644 --- a/dotcom-rendering/src/components/AppsAudioPlayButton.tsx +++ b/dotcom-rendering/src/components/AudioPlayer/AppsAudioPlayButton.tsx @@ -1,4 +1,4 @@ -import { ListenToArticleButton } from './ListenToArticleButton'; +import { ListenToArticleButton } from '../ListenToArticleButton'; type Props = { onClickHandler: () => void; diff --git a/dotcom-rendering/src/components/AudioPlayer/AudioPlayer.stories.tsx b/dotcom-rendering/src/components/AudioPlayer/AudioPlayer.stories.tsx index 48ba6633dd7..bbbc3c5c339 100644 --- a/dotcom-rendering/src/components/AudioPlayer/AudioPlayer.stories.tsx +++ b/dotcom-rendering/src/components/AudioPlayer/AudioPlayer.stories.tsx @@ -1,7 +1,7 @@ import { defaultFormats } from '../../../.storybook/decorators/splitThemeDecorator'; import { allModes } from '../../../.storybook/modes'; import preview from '../../../.storybook/preview'; -import { AudioPlayer as Player } from './AudioPlayer'; +import { AudioPlayerWeb as Player } from './AudioPlayerWeb.island'; // import audioFile from './stories/default_audio_test.mp3'; const meta = preview.meta({ @@ -14,6 +14,8 @@ export const AudioPlayer = meta.story({ // src: audioFile, src: 'https://audio.guim.co.uk/2024/10/18-57753-USEE_181024.mp3', mediaId: 'mediaId', + contentIsNotSensitive: true, + isAcastEnabled: true, }, parameters: { // We only want to snapshot the `multipleFormats` version below. diff --git a/dotcom-rendering/src/components/AudioPlayer/AudioPlayer.tsx b/dotcom-rendering/src/components/AudioPlayer/AudioPlayer.tsx index 860317fea42..8c4130fa553 100644 --- a/dotcom-rendering/src/components/AudioPlayer/AudioPlayer.tsx +++ b/dotcom-rendering/src/components/AudioPlayer/AudioPlayer.tsx @@ -1,308 +1,55 @@ -import { log } from '@guardian/libs'; -import type { AudioEvent, TAudioEventType } from '@guardian/ophan-tracker-js'; -import { useCallback, useEffect, useRef, useState } from 'react'; -import { getOphan } from '../../client/ophan/ophan'; -import { Playback } from './components/Playback'; -import { ProgressBar } from './components/ProgressBar'; -import { CurrentTime, Duration } from './components/time'; -import { Wrapper } from './components/Wrapper'; +import { css } from '@emotion/react'; +import { space } from '@guardian/source/foundations'; +import { StraightLines } from '@guardian/source-development-kitchen/react-components'; +import { palette } from '../../palette'; +import { Island } from '../Island'; +import { formatAudioDuration } from '../ListenToArticle.island'; +import { AudioPlayerApps } from './AudioPlayerApps.island'; +import { AudioPlayerWeb } from './AudioPlayerWeb.island'; -// ********************* ophan stuff ********************* - -// possible events for audio in ophan -type AudioEvents = TAudioEventType extends `audio:content:${infer E}` - ? E - : never; - -// possible progress events for audio in ophan -type AudioProgressEvents = - Extract extends `${infer N extends number}` - ? N - : never; - -const reportAudioEvent = (mediaId: string, eventName: AudioEvents) => { - const audioEvent: AudioEvent = { - id: mediaId, - eventType: `audio:content:${eventName}`, - }; - - void getOphan('Web').then((ophan) => { - ophan.record({ - audio: audioEvent, - }); - }); -}; - -// ********************* Component ********************* - -type AudioPlayerProps = { - /** The audio source you want to play. */ - src: string; - /** - * Optional, pre-computed duration of the audio source. - * If it's not provided it will be calculated once the audio is loaded. - */ - duration?: number; - /** media element ID for Ophan */ - mediaId: string; -}; - -/** - * Audio player component. - */ export const AudioPlayer = ({ - src, - duration: preCalculatedDuration, - mediaId, -}: AudioPlayerProps) => { - // ********************* player ********************* - - // state for displaying feedback to the user - const [isPlaying, setIsPlaying] = useState(false); - const [currentTime, setCurrentTime] = useState(0); - const [duration, setDuration] = useState(preCalculatedDuration); - const [progress, setProgress] = useState(0); - const [isWaiting, setIsWaiting] = useState(false); - const [isScrubbing, setIsScrubbing] = useState(false); - const [buffer, setBuffer] = useState(0); - - const isFirstPlay = useRef(true); - - // ref to the