VideoJSPluginOptions
} from './peertube-videojs-typings'
import { TranslationsManager } from './translations-manager'
-import { buildVideoOrPlaylistEmbed, buildVideoLink, copyToClipboard, getRtcConfig, isIOS, isSafari } from './utils'
+import { buildVideoOrPlaylistEmbed, buildVideoLink, copyToClipboard, getRtcConfig, isSafari, isIOS } from './utils'
// Change 'Playback Rate' to 'Speed' (smaller for our settings menu)
(videojs.getComponent('PlaybackRateMenuButton') as any).prototype.controlText_ = 'Speed'
videoViewUrl: string
embedUrl: string
+ isLive: boolean
+
language?: string
videoCaptions: VideoJSCaption[]
private static playerElementClassName: string
private static onPlayerChange: (player: videojs.Player) => void
+ private static alreadyPlayed = false
+
+ static initState () {
+ PeertubePlayerManager.alreadyPlayed = false
+ }
+
static async initialize (mode: PlayerMode, options: PeertubePlayerManagerOptions, onPlayerChange: (player: videojs.Player) => void) {
let p2pMediaLoader: any
alreadyFallback = true
})
+ player.one('play', () => {
+ PeertubePlayerManager.alreadyPlayed = true
+ })
+
self.addContextMenu(mode, player, options.common.embedUrl)
player.bezels()
p2pMediaLoaderModule?: any
): videojs.PlayerOptions {
const commonOptions = options.common
+ const isHLS = mode === 'p2p-media-loader'
let autoplay = this.getAutoPlayValue(commonOptions.autoplay)
let html5 = {}
PeertubePlayerManager.addHotkeysOptions(plugins)
}
- if (mode === 'p2p-media-loader') {
+ if (isHLS) {
const { hlsjs } = PeertubePlayerManager.addP2PMediaLoaderOptions(plugins, options, p2pMediaLoaderModule)
html5 = hlsjs.html5
const p2pMediaLoaderConfig = {
loader: {
trackerAnnounce,
- segmentValidator: segmentValidatorFactory(options.p2pMediaLoader.segmentsSha256Url),
+ segmentValidator: segmentValidatorFactory(options.p2pMediaLoader.segmentsSha256Url, options.common.isLive),
rtcConfig: getRtcConfig(),
- requiredSegmentsPriority: 5,
+ requiredSegmentsPriority: 1,
segmentUrlBuilder: segmentUrlBuilderFactory(redundancyUrlManager),
useP2P: getStoredP2PEnabled(),
consumeOnly
const resolution = Math.min(level.height || 0, level.width || 0)
const file = p2pMediaLoaderOptions.videoFiles.find(f => f.resolution.id === resolution)
- if (!file) {
- console.error('Cannot find video file for level %d.', level.height)
- return level.height
- }
+ // We don't have files for live videos
+ if (!file) return level.height
let label = file.resolution.label
if (file.fps >= 50) label += file.fps
hlsjsConfig: {
capLevelToPlayerSize: true,
autoStartLoad: false,
- liveSyncDurationCount: 7,
+ liveSyncDurationCount: 5,
loader: new p2pMediaLoaderModule.Engine(p2pMediaLoaderConfig).createLoaderClass()
}
}
const commonOptions = options.common
const webtorrentOptions = options.webtorrent
+ const autoplay = this.getAutoPlayValue(commonOptions.autoplay) === 'play'
+ ? true
+ : false
+
const webtorrent = {
- autoplay: commonOptions.autoplay,
+ autoplay,
videoDuration: commonOptions.videoDuration,
playerElement: commonOptions.playerElement,
videoFiles: webtorrentOptions.videoFiles,
private static getAutoPlayValue (autoplay: any) {
if (autoplay !== true) return autoplay
- // Giving up with iOS
- if (isIOS()) return false
-
- // We have issues with autoplay and Safari.
- // any that tries to play using auto mute seems to work
- if (isSafari()) return 'any'
+ // On first play, disable autoplay to avoid issues
+ // But if the player already played videos, we can safely autoplay next ones
+ if (isIOS() || isSafari()) {
+ return PeertubePlayerManager.alreadyPlayed ? 'play' : false
+ }
return 'play'
}