Skip to content

Commit 6c24116

Browse files
committed
Exclude ogg audio source on mobile Safari
iOS 18.4 claims to introduce support for ogg files. Safari selects the ogg source, fails to load the file, though. Previous Safari versions selected the mp3 source. REDMINE-21034
1 parent 7c97b42 commit 6c24116

File tree

7 files changed

+66
-6
lines changed

7 files changed

+66
-6
lines changed

entry_types/paged/packages/pageflow-paged-react/src/media/components/AudioFilePlayer.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ import createFilePlayer from './createFilePlayer';
33
export 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
});

entry_types/paged/packages/pageflow-paged-react/src/media/components/__spec__/createFilePlayer-spec.jsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff 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}) => [

entry_types/paged/packages/pageflow-paged-react/src/media/components/createFilePlayer/index.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff 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
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
});

entry_types/scrolled/package/src/frontend/AudioPlayer/index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react';
22
import classNames from 'classnames';
3+
import {browser} from 'pageflow/frontend';
34

45
import {MediaPlayer} from '../MediaPlayer';
56
import {useTextTracks} from '../useTextTracks';
@@ -52,7 +53,7 @@ AudioPlayer.defaultProps = {
5253

5354
export 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+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
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+
});

package/src/frontend/browser/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
21
import {agent, Agent} from './Agent';
32
import {browser} from './browser';
43

4+
import './audio';
55
import './autoplaySupport';
66
import './cssAnimations';
77
import './facebook';
@@ -18,4 +18,4 @@ import './volumeControlSupport';
1818
export * from './browser';
1919

2020
browser.agent = agent;
21-
browser.Agent = Agent;
21+
browser.Agent = Agent;

0 commit comments

Comments
 (0)