X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;ds=sidebyside;f=client%2Fsrc%2Fassets%2Fplayer%2Fpeertube-player-manager.ts;h=fcf0d0f4158eb42c573c5523d1635c1167386f63;hb=cb5c2abc99c2e222fe18621f79cb68b805678e15;hp=15b2f420b17b74f016a0aab81702c480aee5f50a;hpb=951b582f52d0694865f020f0e53ccfad2d2d6033;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/src/assets/player/peertube-player-manager.ts b/client/src/assets/player/peertube-player-manager.ts index 15b2f420b..fcf0d0f41 100644 --- a/client/src/assets/player/peertube-player-manager.ts +++ b/client/src/assets/player/peertube-player-manager.ts @@ -35,7 +35,8 @@ import { VideoJSPluginOptions } from './peertube-videojs-typings' import { TranslationsManager } from './translations-manager' -import { buildVideoOrPlaylistEmbed, buildVideoLink, copyToClipboard, getRtcConfig, isIOS, isSafari } from './utils' +import { buildVideoOrPlaylistEmbed, buildVideoLink, getRtcConfig, isSafari, isIOS } from './utils' +import { copyToClipboard } from '../../root-helpers/utils' // Change 'Playback Rate' to 'Speed' (smaller for our settings menu) (videojs.getComponent('PlaybackRateMenuButton') as any).prototype.controlText_ = 'Speed' @@ -98,6 +99,8 @@ export interface CommonOptions extends CustomizationOptions { videoViewUrl: string embedUrl: string + isLive: boolean + language?: string videoCaptions: VideoJSCaption[] @@ -117,6 +120,12 @@ export class PeertubePlayerManager { 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 @@ -152,6 +161,10 @@ export class PeertubePlayerManager { alreadyFallback = true }) + player.one('play', () => { + PeertubePlayerManager.alreadyPlayed = true + }) + self.addContextMenu(mode, player, options.common.embedUrl) player.bezels() @@ -202,6 +215,7 @@ export class PeertubePlayerManager { p2pMediaLoaderModule?: any ): videojs.PlayerOptions { const commonOptions = options.common + const isHLS = mode === 'p2p-media-loader' let autoplay = this.getAutoPlayValue(commonOptions.autoplay) let html5 = {} @@ -209,13 +223,14 @@ export class PeertubePlayerManager { const plugins: VideoJSPluginOptions = { peertube: { mode, - autoplay, // Use peertube plugin autoplay because we get the file by webtorrent + autoplay, // Use peertube plugin autoplay because we could get the file by webtorrent videoViewUrl: commonOptions.videoViewUrl, videoDuration: commonOptions.videoDuration, userWatching: commonOptions.userWatching, subtitle: commonOptions.subtitle, videoCaptions: commonOptions.videoCaptions, - stopTime: commonOptions.stopTime + stopTime: commonOptions.stopTime, + isLive: commonOptions.isLive } } @@ -227,7 +242,7 @@ export class PeertubePlayerManager { PeertubePlayerManager.addHotkeysOptions(plugins) } - if (mode === 'p2p-media-loader') { + if (isHLS) { const { hlsjs } = PeertubePlayerManager.addP2PMediaLoaderOptions(plugins, options, p2pMediaLoaderModule) html5 = hlsjs.html5 @@ -312,9 +327,9 @@ export class PeertubePlayerManager { 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 @@ -328,10 +343,8 @@ export class PeertubePlayerManager { 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 @@ -342,7 +355,7 @@ export class PeertubePlayerManager { hlsjsConfig: { capLevelToPlayerSize: true, autoStartLoad: false, - liveSyncDurationCount: 7, + liveSyncDurationCount: 5, loader: new p2pMediaLoaderModule.Engine(p2pMediaLoaderConfig).createLoaderClass() } } @@ -358,8 +371,12 @@ export class PeertubePlayerManager { 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, @@ -579,12 +596,11 @@ export class PeertubePlayerManager { 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' }