this.startTime = timeToInt(options.startTime)
// Disable auto play on iOS
- this.autoplay = options.autoplay && isIOS() === false
+ this.autoplay = options.autoplay
this.playerRefusedP2P = !getStoredP2PEnabled()
this.videoFiles = options.videoFiles
done: () => void = () => { /* empty */ }
) {
// Automatically choose the adapted video file
- if (videoFile === undefined) {
+ if (!videoFile) {
const savedAverageBandwidth = getAverageBandwidthInStore()
videoFile = savedAverageBandwidth
? this.getAppropriateFile(savedAverageBandwidth)
: this.pickAverageVideoFile()
}
+ if (!videoFile) {
+ throw Error(`Can't update video file since videoFile is undefined.`)
+ }
+
// Don't add the same video file once again
if (this.currentVideoFile !== undefined && this.currentVideoFile.magnetUri === videoFile.magnetUri) {
return
options: PlayOptions,
done: Function
) {
+ if (!magnetOrTorrentUrl) return this.fallbackToHttp(options, done)
+
console.log('Adding ' + magnetOrTorrentUrl + '.')
const oldTorrent = this.torrent
private tryToPlay (done?: (err?: Error) => void) {
if (!done) done = function () { /* empty */ }
- // Try in mute mode because we have issues with Safari
- if (isSafari() && this.player.muted() === false) {
- this.player.muted(true)
- }
-
const playPromise = this.player.play()
if (playPromise !== undefined) {
return playPromise.then(() => done())
if (this.webtorrent.downloadSpeed !== 0) this.downloadSpeeds.push(this.webtorrent.downloadSpeed)
return this.player.trigger('p2pInfo', {
+ source: 'webtorrent',
http: {
downloadSpeed: 0,
uploadSpeed: 0,
uploadSpeed: this.torrent.uploadSpeed,
downloaded: this.torrent.downloaded,
uploaded: this.torrent.uploaded
- }
+ },
+ bandwidthEstimate: this.webtorrent.downloadSpeed
} as PlayerNetworkInfo)
}, this.CONSTANTS.INFO_SCHEDULER)
}
private pickAverageVideoFile () {
if (this.videoFiles.length === 1) return this.videoFiles[0]
- return this.videoFiles[Math.floor(this.videoFiles.length / 2)]
+ const files = this.videoFiles.filter(f => f.resolution.id !== 0)
+ return files[Math.floor(files.length / 2)]
}
private stopTorrent (torrent: WebTorrent.Torrent) {
}
private changeQuality () {
- const resolutionId = this.currentVideoFile.resolution.id
+ const resolutionId = this.currentVideoFile.resolution.id as number
const qualityLevels = this.player.qualityLevels()
if (resolutionId === -1) {