Skip to content

Instantly share code, notes, and snippets.

@obliviusm
Created October 19, 2018 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save obliviusm/4042d895185e7b466bb9263e9cb5cafc to your computer and use it in GitHub Desktop.
Save obliviusm/4042d895185e7b466bb9263e9cb5cafc to your computer and use it in GitHub Desktop.
import React, { Component } from 'react'
import { Video } from 'expo'
import VideoPlayer from '@expo/videoplayer'
import { Actions } from 'react-native-router-flux'
import api from '../../services/FixtureApi'
import Spinner from '../Spinner'
interface Props {
id: string
}
class Playback extends Component<Props, {}> {
constructor() {
super()
this.state = {
videoName: '',
uri: '',
nextVideoId: '',
isLoading: false,
}
}
componentDidMount() {
this.getVideo(this.props.id)
}
isFinish = playbackStatus => {
const { durationMillis, positionMillis } = playbackStatus
if (durationMillis === positionMillis && positionMillis > 0) {
this.setState({
isLoading: false,
})
this.getVideo(this.state.nextVideoId)
}
}
async getVideo(videoId) {
const response = await api.getVideo(videoId)
if (response.ok) {
this.setState({
videoName: response.data.name,
uri: response.data.uri,
nextVideoId: response.data.nextVideoId,
isLoading: true,
})
} else {
alert(response.data.error)
Actions.pop()
}
}
render() {
if (!this.state.isLoading) {
return <Spinner />
}
return (
<VideoPlayer
videoProps={{
shouldPlay: true,
resizeMode: Video.RESIZE_MODE_CONTAIN,
source: {
uri: this.state.uri,
},
}}
switchToPortrait={() => Actions.pop()}
title={this.state.videoName}
backButtonCallback={() => Actions.pop()}
playbackCallback={this.isFinish}
/>
)
}
}
export default Playback
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment