The video in the TypeScript code within the Owl Carousel is not displaying properly - only the sound is playing. The video screen remains stationary

I recently updated my query. I am facing an issue while trying to play a video in Owl Carousal with a button click. The video plays sporadically, and most of the time it doesn't work properly. When playing without the carousel, a single video works fine. Could there be a CSS-related problem with the owl carousal causing this issue? I have checked the console and can see the correct video elements. Although the video appears to be playing as I can hear the sound, the video screen is often stuck.

Below is the HTML code I am using:

I am attempting to create a play button that triggers the function playVideo()

 <div class="big_img mediaCursor" *ngIf="post.mediaData && post.mediaData.length > 1 && post.post_type == 'is_post'" >
        <owl-carousel-o [options]="customOptions1"  #owlCarousel (change)="handleSlide($event)">
          <ng-container *ngFor="let img of post.mediaData"  >
            <ng-template class="slide"  carouselSlide>
              <button  *ngIf="img.media_type === 'video'" class="btn-play-video" id="video_play_{{img.id}}" (click)="playVideo(img.id)">
                <i class="ti ti-control-play"></i>Play
              </button>
              <div class="mb-0 testtts" id="parentVideo_{{img.id}}" >
                <img *ngIf="img.media_type === 'image'" (click)="Openpost(post.post_id)" [src]="img.file_path" alt="Icelandic"
                  class="big_img img-fluid cursor"  />
                  <video id="video_{{img.id}}" width="640"  controls preload="none"    poster="{{img.video_thumb}}"
                    *ngIf="img.media_type === 'video'" class="video-js vjs-default-skin cursor"
                    >
                    <source src="{{ img.file_path }}#t=1" type="video/mp4" />
                  </video>
              </div>
            </ng-template>
          </ng-container>
        </owl-carousel-o>
      </div>

Here is my typescript for the playVideo() function:

  playVideo(eleId){
   let button:HTMLButtonElement = document.querySelector('#video_play_' + eleId)
   let video:HTMLVideoElement =  document.querySelector('#video_' + eleId)
   let parentDiv:HTMLDivElement = document.querySelector('#parentVideo_' + eleId)
   let ddVHeight = parentDiv.offsetHeight
   video.load();
  video.onloadeddata = (event) => {
    video.play()
   this.renderer.setStyle(parentDiv, "height", `${ddVHeight}px`);
    this.renderer.listen(video, 'playing', () => {
     this.renderer.addClass(button, 'hide');
   })
   this.renderer.listen(video, 'pause', () => {
     this.renderer.removeClass(button, 'hide');
   })
    
};

  }

Any suggestions or hints would be greatly appreciated. Thank you.

Answer №1

Try moving the video.play() function outside of the onloadeddata event listener, eliminating the need for video.load()

After calling video.play(), consider checking if there are any errors by handling it as a promise:

video.play().then(console.log).catch(console.log)

Also, make sure to monitor the dev tools console for any potential errors
Which specific browser are you testing this on?

Answer №2

After encountering a challenge, I managed to resolve it independently. It appears that direct owl carousels do not support video playback simply by using the video.play() method for the video element.

To overcome this, I experimented with retrieving a video element based on the owl carousel class owl-item. I had to assign a unique ID to each owl carousel on the page since there are multiple carousels and their count increases with each API call.

Below is the TypeScript function I implemented:

 playVideo2(ele:any) {
    let cc:any = '.owl-' + ele + ' .owl-item.active video'
    if (this.owlCarousel) {
      const videoElement = document.querySelector(cc) as HTMLVideoElement | null;
      if (videoElement) {
        videoElement.play(); 
      }
    }
  }

For the HTML structure, here is an example snippet:

  <div class="big_img mediaCursor owl-{{post.post_id}}" *ngIf="post.mediaData && post.mediaData.length > 1 && post.post_type == 'is_post'" >
        <owl-carousel-o [options]="customOptions1"  #owlCarousel (change)="handleSlide($event)">
          <ng-container *ngFor="let img of post.mediaData"  >
            <ng-template class="slide"  carouselSlide>
              <button  *ngIf="img.media_type === 'video'" class="btn-play-video" id="video_play_{{img.id}}" (click)="playVideo2(post.post_id)">
                <i class="ti ti-control-play"></i>Play
              </button>
              <div class="mb-0 testtts" id="parentVideo_{{img.id}}" >
                <img *ngIf="img.media_type === 'image'" (click)="Openpost(post.post_id)" [src]="img.file_path" alt="Icelandic"
                  class="big_img img-fluid cursor"  />
                  <video id="video_{{img.id}}" width="640" height=""  controls preload="metadata"    poster="{{img.video_thumb}}"
                    *ngIf="img.media_type === 'video'" class="video-js vjs-default-skin cursor"
                    >
                    <source src="{{ img.file_path }}#t=1" type="video/mp4" />
                  </video>
              </div>
            </ng-template>
          </ng-container>
        </owl-carousel-o>
      </div>

I trust this insight will prove valuable for others facing similar implementation challenges.

Answer №3

Avoid storing conditions in your table; instead, store the data separately like

$workshop_sales and 1600000 in individual columns.

Once you have done that, you can create conditions such as:

"if($row10["open_condition"] > $row10["open_condition_value"]){ //your code }"

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

The GET request on the Express route is malfunctioning, causing the Postman request to time out after getting stuck for some

My Express app seems to be experiencing some issues with the GET route. When making a request using Postman, the response gets stuck for a while before fetching. The GET route is properly set up with all necessary request parsers and the app initialized an ...

Cookies are strangely absent from the ajax call to the web api - a puzzling issue indeed for Web Api users

Hello, here is the code I'm working with using Ajax: function GetCurrentUserId() { return $.ajax({ type: "GET", url: rootUrl + '/api/Common/CurrentDateAndUser', dataType: 'json', ...

Using jQuery's $.ajax() function to make an asynchronous request, and then passing the

I'm currently utilizing the jQuery $.ajax() function within a parent function that passes values into the ajax call. I am looking to have a custom callback function that can access the data parameter returned from the success function of the ajax call ...

Make sure to attach a resize event handler just once

I am working with a widget that inserts a div element into the DOM. This div requires some JavaScript to handle the resize event effectively. Here's the issue: The widget may be added multiple times on the same page, but I want to avoid adding re ...

Obtaining the value of cookies in express js is a simple task that

Is there a way to retrieve the value of a cookie? const cookieParser = require('cookie-parser'); app.use(cookieParser()); app.get('/', (req, res) => { res.setHeader('Set-Cookie', 'Cookie=HELLO'); }); I' ...

Encountering issues with MatToolbar in Angular 9 causes unexpected errors

Running Angular version 9.2.0 Encountering an issue while importing the MatToolbarModule in a module and utilizing it in the HTML template. The error message reads as follows: This could indicate that the library (@angular/material/toolbar) that declar ...

How can I implement a search box on my HTML website without relying on Google Custom Search?

Greetings to all! I am currently managing a website filled with HTML content. I am looking to incorporate a search box into the site. After researching on Google, most of the results point towards using Google Custom Search. However, I require a search box ...

Nodejs: A function is expected in the instanceof check, but an undefined value was provided

Encountering a peculiar error while using node-webkit, here's a detailed example to replicate it: index.js: var jQuery = require('jquery'); var Backbone = require('backbone'); (function($){ var ListView = Backbone.View.extend( ...

Exploring cookies to extract and display my email using Express.js

I am currently working on retrieving the name and value fields as cookies through a loop in my app.get method, then posting the field values in the app.post method using expressjs. I would appreciate it if someone could review the 'for loop' bel ...

Show picture in web browser without the file extension

Is there a way to display an image in the browser without the file extension, similar to how Google and Unsplash do it? For example: Or like this: ...

How to use jQuery to iterate over changing elements and retrieve their data values

Exploring the potential of a collapsible panel to meet my requirements $(".sport").on("click", function() { var thisId = $(this).attr("id"); var thisChildren = $(this) + ".sportlist"; $(thisChildren).each(function(index) { }); }); <link ...

Unlimited scrolling feature on a pre-filled div container

Looking for a way to implement infinite scroll on a div with a large amount of data but struggling to find the right solution? I've tried various jQuery scripts like JScroll, MetaFizzy Infinite Scroll, and more that I found through Google search. Whi ...

Encountering an obscure issue when using Discord.js v14 after attempting to cancel and resubmit a modal

I'm currently working on a Discord bot using modals in Discord.js v14. These modals appear after the user clicks a button, and an .awaitModalSubmit() collector is triggered to handle one modal submission interaction by applying certain logic. The .awa ...

Guide on integrating the plyr npm module for creating a video player in Angular2

Looking to implement the Plyr npm package in an Angular 6 application to create a versatile video player capable of streaming m3u8 and Youtube videos. The demos on their npm page are written in plain JavaScript, so I need guidance on how to integrate it in ...

Best practices for alerting using React and Redux

As I delve into Redux for the first time and work on revamping a fairly intricate ReactJS application using Redux, I've decided to create a "feature" for handling notifications. This feature will involve managing a slice of state with various properti ...

Leveraging Vue mixin within a @Component

After implementing the vue-property-decorator package, I encountered an issue when trying to use a mixin method inside the beforeRouteEnter hook. Here is what I initially tried: import { Component, Mixins } from 'vue-property-decorator'; import ...

Issue: 040A1079 - Failure in RSA Padding Check with PKCS1 OAEP MGF1 Decoding Error Detected on Amazon Web Services

Utilizing the crypto package, I execute the following tasks: Using crypto.generateKeyPairSync() to create publicKey and privateKey The keys are generated only once and stored in the .env file Applying crypto.publicEncrypt() to encrypt data before savin ...

What is the correct way to forcefully override an existing type in TypeScript?

As I work with Formik, a React form library, I find myself creating custom fields and utilizing the generic Schema type provided by Formik. This type represents the values object, which holds all the values for each field in the form. One of the custom co ...

Create an input element using JavaScript/jQuery

Looking for some help with Javascript on a simple task. When a specific option is chosen, I want to add an input field to a div element. <select name="amount" > <option value="50">50$</option> <option value="100">100$</o ...

Struggling with inserting a fresh form into every additional <div> section

During my quest to develop a To-Do list application, I encountered a new challenge. In my current implementation, every time a user clicks on New Category, a new div is supposed to appear with a custom name and a specific number of forms. However, an issu ...