Skip to content

Instantly share code, notes, and snippets.

Created January 15, 2020 03:04
What would you like to do?
import React from 'react';
import { TouchableOpacity, View, Text } from 'react-native';
import GoogleCast, { CastButton } from 'react-native-google-cast';
class MyChromecastApp extends React.Component {
// Play the casting, only if the device is connected and was playing something before in the actual sesion
playCast = () =>;
// Pause the currently casting
pauseCast = () => GoogleCast.pause();
// Show the Expanded Control Panel
shwoControls = () => GoogleCast.launchExpandedControls();
// Start the cast with selected media passed by function parameter
startCast = (video, image, title, subtitle, duration, currentTime, mediaType, moreDetails) => {
mediaUrl: video, // Stream media video uri
imageUrl: image, // Image video representative uri
title, // Media main title
subtitle, // Media subtitle
studio: 'Asap Developers', // Media or app owner
streamDuration: duration, // Stream duration in seconds
contentType: mediaType, // Optional media type, default is 'video/mp4'
playPosition: currentTime, // Stream play position in seconds
customData: {
// Optional, your custom object that will be passed to as customData to reciever
mediaDetails: moreDetails,
.then(console.log('Playing.. '))
.catch(e => console.log('An error has ocurred, reason: ', e));
render() {
return (
<Text>Connect with chromecast device with the button above:</Text>
<CastButton style={{ width: 30, height: 30 }} />
<Text>If the conecction was successfully, you are ready to send content now:</Text>
<TouchableOpacity onPress={() => this.startCast('video.mp4', 'video_image.jpg', 'Asap Sample Video', '-', 120, 0, 'video/mp4', 'No details')}>
<Text>Send my video</Text>
export default MyChromecastApp;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment