When the video message bubble is touched within the chat app, a video player will automatically pop up (using React Native)

Currently, I am developing a chat app in React Native that can handle the sending and receiving of video files. However, I am facing challenges with activating the video player when a user presses on the video message inside the chat bubble. Despite my attempts to write the necessary code, I have not been successful so far. Below is an excerpt of the relevant code snippet where I have replaced the videoUrl with "http://d23dyxeqlo5psv.cloudfront.net/big_buck_bunny.mp4" for testing purposes.

import { Video } from "expo-av";

.
.
.
const [modalVisible, setModalVisible] = React.useState(false);
.
.
.

//Upon pressing the videoThumbnailUrl bubble, the video file should play
{videoThumbnailUrl && (
        <TouchableOpacity
          onPress={() => {
            setModalVisible(true);
            return (
              <View
                style={{
                  flex: 1,
                  backgroundColor: "red",
                  justifyContent: "center",
                }}
              >
                <Modal
                  visible={modalVisible}
                  onRequestClose={() => {
                    setModalVisible(!modalVisible);
                  }}
                >
                  <View style={{ backgroundColor: "white", flex: 1 }}>
                    <Video
                      source={{
                        uri: "http://example.com/video.mp4",
                      }}
                      style={{ height: 300, width: 300, opacity: 0.5 }}
                    />
                  </View>
                </Modal>
              </View>
            );
          }}
        >
          <ImageBackground
            source={{ uri: videoThumbnailUrl }}
            resizeMode="cover"
            style={styles.image}
          >
            <AntDesign name="playcircleo" color="white" size={80} />
          </ImageBackground>
        </TouchableOpacity>
      )}

Despite setting up the functionality for the video player to appear and play the video upon clicking the video message bubble in my chat app, no action is triggered. This issue is something I need to resolve for better user experience.

Answer №1

Could you please give this a shot?

{videoThumbnailUrl && (
   
<TouchableOpacity

   onPress={() => {
        setModalVisible(true);
       
      }}
    >
      <ImageBackground
        source={{ uri: videoThumbnailUrl }}
        resizeMode="cover"
        style={styles.image}
      >
        <AntDesign name="playcircleo" color="white" size={80} />
      </ImageBackground>
    </TouchableOpacity>

}

{
    modalVisible &&
    <View
    style={{
      flex: 1,
      backgroundColor: "red",
      justifyContent: "center",
    }}
  >
    <Modal
      visible={modalVisible}
      onRequestClose={() => {
        setModalVisible(!modalVisible);
      }}
    >
      <View style={{ backgroundColor: "white", flex: 1 }}>
        <Video
          source={{
            uri: "http://d23dyxeqlo5psv.cloudfront.net/big_buck_bunny.mp4",
          }}
          style={{ height: 300, width: 300, opacity: 0.5 }}
        />
      </View>
    </Modal>
  </View>
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips on adding an image using Reactjs

I am currently working in Reactjs with the Next.js framework. I am attempting to upload images using Axios (POST method API) and will be utilizing an "api in PHP". Could someone please guide me on how to achieve this? I have tried the code below, but it&ap ...

Display a modal before leaving the page?

I need to display a modal message when a user navigates away from the page, triggered by a successful AJAX call. The issue is that if the message loads too quickly, the user may not have enough time to read it before being directed to another page. This is ...

What is the right time to use parentheses when calling functions - and when should you leave them

Currently, I am following along with a tutorial at this link and I've come across some syntax that is confusing to me. The goal is to have "hello" logged to the console every time I scroll. function moveCamera() { console.log("hello"); } document. ...

In React using Flow Type, the syntax [...mySet] doesn't function as expected, while Array.from(mySet) successfully converts the

Why is it that with React and Flow Type, the line of code displaying [{}] when using JSON.stringify([...mySet]) but shows the correct values with JSON.stringify(Array.from(mySet))? The issue seems perplexing as this behavior cannot b ...

Next.js fails to load TailwindCSS

I am in the process of developing an app using tailwindcss and next.js First, I started creating the nextjs app, then I executed these commands: npm install -D tailwindcss postcss autoprefixer npx tailwindcss init -p Following that, I made adjustments t ...

Comparison of utilizing PHP within CSS versus Implementation through JavaScript [General]

Curious about the incorporation of PHP in CSS, especially in relation to my current Wordpress Theme project. I am aiming for high levels of customization and have been using a JS file to change CSS Properties through PHP. However, I'm not entirely con ...

Error encountered on NodeJS server

Today marks my third day of delving into the world of Angular. I've come across a section that covers making ajax calls, but I've hit a roadblock where a tutorial instructed me to run server.js. I have successfully installed both nodejs and expre ...

The issue of Jquery selectors not functioning properly when used with variables

Currently working on a script in the console that aims to extract and display the user's chat nickname. Initially, we will attempt to achieve this by copying and pasting paths: We inspect the user's name in the Chrome console and copy its selec ...

"Exploring the Functionality of Page Scrolling with

Utilizing Codeigniter / PHP along with this Bootstrap template. The template comes with a feature that allows for page scrolling on the homepage. I have a header.php template set up to display the main navigation across all pages. This is the code for th ...

Transform and command the data acquired through an AJAX request using jQuery

My code includes an AJAX call using jQuery: $('.add a').click(function() { $.ajax({ type: 'POST', url: '/api/fos', context: this, datatype: 'html', success: function(data) ...

Is it possible for Angular2 to map a lone JSON object?

Dealing with a JSON response that is a single object, rather than an array, can be tricky. Recently in my project, I encountered a situation where I needed to map and use such a response from an API to fill out a template. It seemed like a simple task at f ...

Button in HTML not functioning as expected

I have 3 different files that are crucial for my webpage to function properly: index.html: <html> <head> </head> <body> <h1>Webpage</h1> <p id = "text">Hello world!</p> <button oncl ...

Find all elements within JSON data using lodash.js

Hello friends, I'm dealing with a JSON object: var companies = [ { id: 1, name: "Test Company", admin: "Test Admin" }, { id: 2, name: "Another Company", admin: "Test Admin", country: 'Spain' }, { id: 3, name: "New Company", ad ...

Guide to creating scroll-based animations for a Div element

I've been brainstorming ways to rotate a div as I scroll. My goal is to recreate the effect shown in this codepen. However, I'm struggling to implement scrolling functionality. What I envision is scrolling down causing the word Data to rotate in ...

VueJS: Send all unspecified attributes to child component in the same way as using v-bind="$props"

I am looking for a way to receive any props passed by the parent component into the child component without explicitly mentioning them in props:[]. This is because I may not always know which props will be bound. Parent component <template> <di ...

I am puzzled as to why my Details Modal keeps appearing whenever I click anywhere, even when I have specifically added it to only show up on the event of today. Additionally, I am encountering

ERROR Function components cannot have string refs. We recommend using useRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref at coerceRef (http://localhost:3000/static/js/bundle.js:59386:21) at createChil ...

Something seems to be amiss with the validation functionality in jQuery

After creating a simple form with input fields and a button, I added validation to display an error message when clicking the apply button without filling out required values. However, the code is not functioning as intended. Even though error messages are ...

Curious about the power of jQuery methods?

I've been coming across codes similar to this: $(document.documentElement).keyup( function(event) { var slides = $('#slides .pagination li'), current = slides.filter('.current'); switch( event.keyCode ) { ...

Is it possible to retrieve an object based on a variable value?

This seems like a simple problem... I possess an object const VR03 = { name: "Eternal Growth Ring", price: "2500" } Within a function, I am assigning a string to a variable function myFunction(){ let js_type = jQuery('#type').val( ...

Completely charting the dimensions of an unfamiliar object (and the most effective method for determining its extent)

I am facing a challenge with a "parent" object that contains an unknown number of children at various depths. My main objective is to efficiently map this "parent" object and all its levels of children. How can I achieve this task? Each child already inc ...