Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.10 KB | None | 0 0
  1. import React from 'react';
  2. import { Text, View, Image } from 'react-native';
  3. import { parseString } from "react-native-xml2js";
  4. import YouTube from 'react-native-youtube';
  5. export default class MovieDetailScreen extends React.Component {
  6.  
  7. // set screen title
  8. static navigationOptions = ({ navigation }) => {
  9. return {
  10. title: `Movie Details`,
  11. };
  12. };
  13.  
  14. // set synopsis state empty, we will load synopsis later
  15. constructor(props) {
  16. super(props);
  17. this.state = { synopsis: '', videoURL: null, status: null };
  18. }
  19.  
  20. // load synopsis, note it is in different XML in finnkino
  21. async loadSynopsis() {
  22. const { navigation } = this.props;
  23. const show = navigation.getParam('show', null);
  24.  
  25. console.log(show.EventID[0]);
  26. let response = await fetch('https://www.finnkino.fi/xml/Events/?eventId=' + show.EventID[0]);
  27. let data = await response.text();
  28. parseString(data, function (err, result) {
  29. console.log("VIDEO: " + result.Events.Event[0].Videos[0].EventVideo[0].Location[0]);
  30. this.setState({ synopsis: result.Events.Event[0].ShortSynopsis, videoURL: result.Events.Event[0].Videos[0].EventVideo[0].Location[0] });
  31. }.bind(this));
  32. }
  33.  
  34.  
  35. // start loading synopsis when component is mounted
  36. componentDidMount() {
  37. this.loadSynopsis();
  38.  
  39. }
  40.  
  41. youtubeOnStateChange (e) {
  42. console.log("STATE CHANGED: " + e);
  43. }
  44.  
  45. // render movie details
  46. render() {
  47. const { navigation } = this.props;
  48. const show = navigation.getParam('show', null);
  49. let imageurl = show.Images[0].EventSmallImageLandscape[0];
  50. console.log("STATUS: " + this.state.status + " Error: " + this.state.error);
  51. return (
  52. <View>
  53. <Image source={{ uri: imageurl }} style={{ aspectRatio: 670 / 250 }} />
  54. <Text>{show.Title}</Text>
  55. <Text>Length: {show.LengthInMinutes} mins</Text>
  56. <Text>Theatre: {show.TheatreAndAuditorium}</Text>
  57. <Text>PresentationMethod: {show.PresentationMethod}</Text>
  58. <Text>Rating: {show.Rating}</Text>
  59. <View style={{ flexDirection: 'row' }}>
  60. <Text style={{ flex: 1, flexWrap: 'wrap' }}>Genres: {show.Genres}</Text>
  61. </View>
  62. <Text>Synopsis: {this.state.synopsis}</Text>
  63. <YouTube
  64. apiKey='AIzaSyAwpMulO85HK2bhtxsCiuuESlnc4ARXEV0'
  65. play={true}
  66. videoId={this.state.videoURL}// The YouTube video ID
  67. onReady={e => this.setState({ isReady: true })}
  68. controls={1}
  69. onChangeState={this.youtubeOnStateChange}
  70. onChangeQuality={e => this.setState({ quality: e.quality })}
  71. onError={e => this.setState({ error: e.error })}
  72. style={{ alignSelf: 'stretch', height: 300 }}
  73. ref='yt'
  74. />
  75. </View>
  76. )
  77. }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement