Skip to content

Instantly share code, notes, and snippets.

@joaquin-viera
Last active July 7, 2021 06:08
Show Gist options
  • Save joaquin-viera/dc96849c2bf0cdd50bea65ffdd571840 to your computer and use it in GitHub Desktop.
Save joaquin-viera/dc96849c2bf0cdd50bea65ffdd571840 to your computer and use it in GitHub Desktop.
Streaming - PlayStream.js
import React, { useState, useEffect } from "react";
import { View, Button } from "react-native";
import { NodePlayerView } from "react-native-nodemediaclient";
const PlayStream = (props) => {
const [playerRef, setPlayerRef] = useState(null);
useEffect(() => {
return () => {
if (playerRef) playerRef.stop();
};
}, []);
return (
<View style={{ flex: 1 }}>
<NodePlayerView
style={{ flex: 1, backgroundColor: "#333" }}
ref={(vp) => {
setPlayerRef(vp);
}}
inputUrl={props.route.params.playserver + props.route.params.stream}
scaleMode={"ScaleAspectFill"}
bufferTime={300}
maxBufferTime={1000}
autoplay={true}
onStatus={(code, msg) => {
console.log("onStatus=" + code + " msg=" + msg);
}}
/>
<Button
onPress={() => {
props.navigation.goBack();
}}
title="Back"
/>
</View>
);
};
export default PlayStream;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment