File tree Expand file tree Collapse file tree 7 files changed +66
-6
lines changed
paged/packages/pageflow-paged-react/src/media/components
spec/frontend/AudioPlayer
package/src/frontend/browser Expand file tree Collapse file tree 7 files changed +66
-6
lines changed Original file line number Diff line number Diff line change @@ -3,11 +3,11 @@ import createFilePlayer from './createFilePlayer';
33export default createFilePlayer ( {
44 tagName : 'audio' ,
55
6- sources : audioFile => [
7- { type : 'audio/ogg' , src : `${ audioFile . urls . ogg } ?u=1` } ,
6+ sources : ( audioFile , _ , { hasBrokenOggSupport } ) => [
7+ ! hasBrokenOggSupport && { type : 'audio/ogg' , src : `${ audioFile . urls . ogg } ?u=1` } ,
88 { type : 'audio/mp4' , src : `${ audioFile . urls . m4a } ?u=1` } ,
99 { type : 'audio/mp3' , src : `${ audioFile . urls . mp3 } ?u=1` }
10- ] ,
10+ ] . filter ( Boolean ) ,
1111
1212 emulateTextTracksDisplay : true
1313} ) ;
Original file line number Diff line number Diff line change @@ -93,6 +93,20 @@ describe('createFilePlayer', () => {
9393 expect ( wrapper . render ( ) ) . toHaveDescendant ( 'source[src="high.mp4"]' ) ;
9494 } ) ;
9595
96+ it ( 'passes hasBrokenOggSupport option to sources' , ( ) => {
97+ const { FilePlayer} = setup ( {
98+ sources : ( file , quality , { hasBrokenOggSupport} ) => [
99+ hasBrokenOggSupport ?
100+ { type : 'audio/mp3' , src : 'audio.mp3' } :
101+ { type : 'audio/ogg' , src : 'audio.ogg' }
102+ ]
103+ } ) ;
104+
105+ const wrapper = mount ( < FilePlayer { ...requiredProps } hasBrokenOggSupport = { true } /> ) ;
106+
107+ expect ( wrapper . render ( ) ) . toHaveDescendant ( 'source[src="audio.mp3"]' ) ;
108+ } ) ;
109+
96110 it ( 'passes forceBestQuality option to sources' , ( ) => {
97111 const { FilePlayer} = setup ( {
98112 sources : ( file , quality , { forceBestQuality} ) => [
Original file line number Diff line number Diff line change @@ -123,6 +123,7 @@ export default function({
123123 sources = { sources ( this . props . file ,
124124 this . props . quality ,
125125 { hasHighBandwidth : this . props . hasHighBandwidth ,
126+ hasBrokenOggSupport : this . props . hasBrokenOggSupport ,
126127 forceBestQuality : this . props . forceBestQuality ,
127128 forceFullhdQuality : this . props . forceFullhdQuality } ) }
128129 tracks = { textTracksFromFiles ( this . props . textTracks . files ,
@@ -163,6 +164,7 @@ export default function({
163164 quality : setting ( { property : 'videoQuality' } ) ,
164165 hasNativeVideoPlayer : has ( 'native video player' ) ,
165166 hasHighBandwidth : has ( 'high bandwidth' ) ,
167+ hasBrokenOggSupport : has ( 'broken ogg support' ) ,
166168 forceBestQuality : isFeatureEnabled ( 'force_best_video_quality' ) ,
167169 forceFullhdQuality : isFeatureEnabled ( 'force_fullhd_video_quality' ) ,
168170 textTrackPosition
Original file line number Diff line number Diff line change 1+ import { processSources } from 'frontend/AudioPlayer' ;
2+ import { browser } from 'pageflow/frontend' ;
3+
4+ describe ( 'AudioPlayer processSources' , ( ) => {
5+ beforeEach ( ( ) => jest . restoreAllMocks ( ) ) ;
6+
7+ it ( 'includes ogg, mp3 and m4a by default' , ( ) => {
8+ const audioFile = { urls : {
9+ 'ogg' : 'http://example.com/4/audio.ogg' ,
10+ 'mp3' : 'http://example.com/4/audio.mp3' ,
11+ 'm4a' : 'http://example.com/4/audio.m4a' ,
12+ } } ;
13+
14+ const result = processSources ( audioFile ) ;
15+
16+ expect ( result . map ( s => s . type ) ) . toEqual ( [ 'audio/ogg' , 'audio/mp3' , 'audio/m4a' ] ) ;
17+ } ) ;
18+
19+ it ( 'excludes ogg source if broken' , ( ) => {
20+ jest . spyOn ( browser , 'has' ) . mockImplementation ( name => name === 'broken ogg support' ) ;
21+
22+ const audioFile = { urls : {
23+ 'ogg' : 'http://example.com/4/audio.ogg' ,
24+ 'mp3' : 'http://example.com/4/audio.mp3' ,
25+ 'm4a' : 'http://example.com/4/audio.m4a' ,
26+ } } ;
27+
28+ const result = processSources ( audioFile ) ;
29+
30+ expect ( result . map ( s => s . type ) ) . toEqual ( [ 'audio/mp3' , 'audio/m4a' ] ) ;
31+ } ) ;
32+ } ) ;
Original file line number Diff line number Diff line change 11import React from 'react' ;
22import classNames from 'classnames' ;
3+ import { browser } from 'pageflow/frontend' ;
34
45import { MediaPlayer } from '../MediaPlayer' ;
56import { useTextTracks } from '../useTextTracks' ;
@@ -52,7 +53,7 @@ AudioPlayer.defaultProps = {
5253
5354export function processSources ( audioFile ) {
5455 var sources = [ ] ;
55- if ( audioFile . urls [ 'ogg' ] ) {
56+ if ( audioFile . urls [ 'ogg' ] && ! has ( 'broken ogg support' ) ) {
5657 sources . push ( { type : 'audio/ogg' , src : `${ audioFile . urls [ 'ogg' ] } ?u=1` } ) ;
5758 }
5859 if ( audioFile . urls [ 'mp3' ] ) {
@@ -63,3 +64,7 @@ export function processSources(audioFile){
6364 }
6465 return sources ;
6566}
67+
68+ function has ( featureName ) {
69+ return typeof window !== 'undefined' && browser . has ( featureName ) ;
70+ }
Original file line number Diff line number Diff line change 1+ import { browser } from './browser' ;
2+ import { agent } from './Agent' ;
3+
4+ browser . feature ( 'broken ogg support' , function ( ) {
5+ // ogg is not supported on iOS < 18.4 and broken on iOS 18.4
6+ return agent . matchesMobileSafari ( ) ; ;
7+ } ) ;
Original file line number Diff line number Diff line change 1-
21import { agent , Agent } from './Agent' ;
32import { browser } from './browser' ;
43
4+ import './audio' ;
55import './autoplaySupport' ;
66import './cssAnimations' ;
77import './facebook' ;
@@ -18,4 +18,4 @@ import './volumeControlSupport';
1818export * from './browser' ;
1919
2020browser . agent = agent ;
21- browser . Agent = Agent ;
21+ browser . Agent = Agent ;
You can’t perform that action at this time.
0 commit comments