Exploring ways to retrieve a video thumbnail with VueJS3

I am currently working on a project to create a simple program that retrieves movies from my AWS-S3 bucket and transforms them into picture thumbnails.

Below is the code I have written:

<template>
   <img :src="imgURL" class="card-top" alt="thumb_nail">   
</template>

<script>
import { defineComponent, ref } from "vue";
export default defineComponent({
  props: {
    url: {
      type: String,
      required: true,
    },
  },
  setup(props) {
    const imgURL = ref("")
    const video = document.createElement("video");
    video.src = props.url;
    video.addEventListener("loadeddata", () => {
      const canvas = document.createElement("canvas");
      const ctx = canvas.getContext("2d");

      ctx.drawImage(video, 0, 0, video.videoWidth, video.videoHeight);

      imgURL.value = ctx.canvas.toDataURL("image/jpeg");
    })
    return { url: props.url, imgURL };
  },
});
</script>

Home.vue

<template>
   <Thumbnail  src="aws-s3_bucket_url" />   
</template>

<script>
import { defineComponent, ref } from "vue";
import Thumbnail from "../components/Thumbnail.vue"
export default defineComponent({
  components: {
    Thumbnail
  }
  });
</script>

Although there are no errors in the code, the image is not displaying. The dimensions are set correctly, but the image is not showing up.

Answer №1

Ensure the URL is valid and that the loadeddata event is triggered.

Test with a sample video URL to confirm it loads successfully.

<template>
  <!-- parent.vue -->
  <VideoComponent url="https://www.example.com/sample.mp4" />
</template>

If you see something in this example, it means the provided prop is not a valid URL when data is loaded.

If not, you may not be rendering this component correctly.

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

Currently working on a script using google-apps-script, open to any suggestions or ideas

Challenge: I am working on creating arrays to store values and iterate until a specific value is reached. Ultimately, this code will be used to match one letter to another, similar to how the WWII Bombe machine functioned, but in a purely digital format. T ...

Incorrect handling of Unix timestamps in AngularJS

I'm facing an issue with timestamps. Let me explain - I have a timestamp coded as 1378028575, which corresponds to Sun, 01 Sep 2013 09:42:55 GMT according to this website. The problem arises when I attempt to format this timestamp using Angular's ...

Material UI - Radio buttons do not properly reflect the current state of the value

I'm diving into the world of full stack development and I'm working on a project to enhance my understanding of frontend programming with React JS and Material UI. Specifically, I've created a Dialog component to send data to the backend, bu ...

Incorporate a custom style sheet into your Express application

Utilizing ejs, express, and parse.com for my web application backend has presented a challenge when it comes to adding stylesheets. Despite searching for solutions, I have not been able to resolve the issue. Sharing my code in hopes of finding a solution. ...

Tips for halting click propagation in VueJS

My dilemma lies within a recursive list (tree) where each element contains a @click="sayHello(el.id)". The challenge arises due to the nested structure of the list, such as: list-element-0-01 ├──list-el-1-01 │ └──list-el-2-01 └──list ...

Getting started with React Native project

Just dipping my toes into the world of React Native and looking for recommendations on the best starter kit/generator to kickstart my projects. Tried out "create-react-native-app" already, but curious if there are any other generators or kits out there tha ...

What are the steps to utilize the feature of "nprogress"?

After successfully installing npm install nprogress in my project, I encountered an issue when trying to refresh the page - the console displayed the following message: hot-dev-client.js:182 [Fast Refresh] done hot-dev-client.js:196 [Fast Refresh] rebuildi ...

Accessing Rails controller information via a JavaScript AJAX request

In the process of developing a rails application, I have implemented code within the controller to interact with an API. Initially, I call the inventories endpoint, followed by separate calls to two other id endpoints (store_id and product_id) in order to ...

Configuration file included in Node.js package for distribution

Someone recommended incorporating Continuous Integration for a pre-existing application (FrontEnd: Node.js - BackEnd: .Net API). At the moment, the API endpoints are hardwired in the .js files which become minified after being built using webpack. I plan ...

Creating dynamic VueFire references is a powerful feature that allows for more flexibility and customization

I am currently exploring the creation of refs dynamically: The initial ref I created works fine as it is hardcoded, but the second one does not seem to work because it is dynamic: firebase: function(){ return { categories: db.ref('categ ...

Error: react-router v4 - browserHistory is not defined

I'm diving into the world of creating my very first React app within Electron (also my first experience with Electron). I have two routes that need to navigate from one to another. Here's the code snippet I am using: Root ReactDOM.render( < ...

When a button is clicked, the v-bind class is no longer applied

Recently, I encountered a puzzling issue that has left me scratching my head. When I pass the class name as a prop to the child component and click the button, all layout styling is lost. However, this problem doesn't occur when I hardcode the class n ...

Avoid triggering a second event: click versus changing the URL hash

One of the pages on my website has tabs that load dynamic content: HTML <ul> <li><a href="#tab-1">TAB 1</li> <li><a href="#tab-2">TAB 2</li> <li><a href="#tab-3">TAB 3</li> </ul&g ...

What is the best way to interpret the final yaml configuration file on Vue pages?

I'm currently working with nuxt and utilizing a config.yml along with an extended file .config.yml. I need to be able to access the final generated config on any page. Is there a way to achieve this? Adding const config = require('config-yml&apo ...

Invoke the router function dynamically

I am looking for a way to simplify route registration without manually writing out app.get('/', function (req, res, next) { }); each time. I want to automate this process by passing in a router object like the one below... { path: '&ap ...

What is the best way to create a select box in React that allows for both single and multiple selections?

I recently started utilizing a new package for generating dynamic forms, which can be found at this link. Upon reading through the documentation, I attempted to create a select box as outlined in the instructions provided here. Despite following the step ...

Interacting with touch events in JavaScript on Android devices

I am facing an issue with my HTML page where a div is meant to function as an on-off switch momentarily. The functionality I have implemented looks like this: $('#btn').mousedown(function() { startAction() }) $('#btn ...

Experiencing difficulty retrieving the variable within a NodeJs function

Currently, I am utilizing the NodeJS postgresql client to retrieve data, iterate through it and provide an output. To accomplish this, I have integrated ExpressJS with the postgresql client. This is a snippet of my code var main_data = an array conta ...

Purging information from JavaScript object

Looking for a way to remove just one piece of data from a JavaScript object in my React app. Here's the structure of the object: state = { data: [] } const contactData = { Datas: { name: "william", email: "<a href="/cdn-cgi/l/email-pr ...

Relentless reloading problems with Ajax on Internet Explorer 7

Currently, I am facing an issue with my AJAX implementation along with executing some JavaScript/jQuery code. The problem is specific to IE7 as it keeps reloading the content repeatedly without stopping, while other browsers work fine. I have tried a coup ...