const React = require('react') const Bitfield = require('bitfield') const prettyBytes = require('prettier-bytes') const TorrentSummary = require('../lib/torrent-summary') const Playlist = require('../lib/playlist') const { dispatch, dispatcher } = require('../lib/dispatcher') const config = require('../../config') // Shows a streaming video player. Standard features + Chromecast + Airplay module.exports = class Player extends React.Component { render () { // Show the video as large as will fit in the window, play immediately // If the video is on Chromecast or Airplay, show a title screen instead const state = this.props.state const showVideo = state.playing.location === 'local' const showControls = state.playing.location !== 'external' return (
{showVideo ? renderMedia(state) : renderCastScreen(state)} {showControls ? renderPlayerControls(state) : null}
) } onComponentWillUnmount () { // Unload the media element so that Chromium stops trying to fetch data const tag = document.querySelector('audio,video') if (!tag) return tag.pause() tag.src = '' tag.load() } } // Handles volume change by wheel function handleVolumeWheel (e) { dispatch('changeVolume', (-e.deltaY | e.deltaX) / 500) } function renderMedia (state) { if (!state.server) return // Unfortunately, play/pause can't be done just by modifying HTML. // Instead, grab the DOM node and play/pause it if necessary // Get the