Guide on importing videojs-offset library

I am working on a component that utilizes video.js and HLS streaming in Angular. The component code is as follows:

import {
  Component,
  ElementRef,
  AfterViewInit,
  ViewChild,
  Input,
  EventEmitter,
  Output
} from '@angular/core';
import * as videojs from 'video.js';
import * as hls from 'videojs-contrib-hls';

require('videojs-offset');

export type VideoPlayerEvent = 'play' | 'pause' | 'ended';

@Component({
  selector: 'app-video-player',
  templateUrl: './video-player.component.html',
  styleUrls: ['./video-player.component.css']
})
export class VideoPlayerComponent implements AfterViewInit {
  @ViewChild('videoPlayer', { static: false })
  videoPlayer: ElementRef;

  @Input()
  videoUrl: string;

  @Input()
  videoType: string;
  
  @Input()
  clipIn: string;

  @Input()
  clipOut: string;

  @Output()
  onPlayerEvent = new EventEmitter<VideoPlayerEvent>();
  videoJsPlayer: videojs.Player;
  constructor() { }
  ngAfterViewInit() {
    if (this.videoUrl) {
      const self = this;
      this.videoJsPlayer = videojs(this.videoPlayer.nativeElement, {}, function () {
        this.on('play', () => self.onPlayerEvent.emit('play'));

        this.on('pause', () => self.onPlayerEvent.emit('pause'));

        this.on('ended', () => self.onPlayerEvent.emit('ended'));
        return hls;
      });
      if(this.clipIn && this.clipOut) {
        this.videoJsPlayer.offset({
          start: this.clipIn,
          end: this.clipOut,
          restart_beginning: false
        });
      }
    }
  }
}

The goal is to use the videojs-offset library to play a specific section of an HLS stream based on the clipIn and clipOut parameters.

During compilation, I encountered the following error:

ERROR in ../../libs/reusable-ui/video-player/src/lib/components/video-player.component.ts:55:28 - error TS2339: Property 'offset' does not exist on type 'Player'.

I suspect it's related to how I imported the library using require('videojs-offset');, which should be correct according to the documentation.

Any insights on what might be missing or causing this issue?

Answer №1

There has been discussion about this issue on Github and the recommended solution is as follows:

To address this, include the following code snippet in your angular.json:

"scripts": [
   "node_modules/video.js/dist/video.js",
   "node_modules/videojs-offset/dist/videojs-offset.js"
]

Instead of using require('videojs-offset');, utilize it globally by referring to window['videojs'].

For further details, please visit https://github.com/cladera/videojs-offset/issues/38

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

Error: NullInjector - The injector encountered an error when trying to inject the Component into the MatDialogRef in the AppModule

When utilizing a component via routing as well as injecting it as the "target" of a modal dialog, I encountered an issue: export class Component1 implements OnInit { constructor(private service: <someService>, public dialogRef: MatDialogRef<Compo ...

Convert an interface type variable to a string representation

I'm just starting to learn angular and I'm attempting to convert my response from an interface type into a string so that I can store it in session storage. However, when I try to save them, they are being stored as [object] in the session storag ...

Encountering an issue with ng serve following the update of Angular, Material, and Bootstrap

Here is the package.json configuration: angular: 5.2.8 angular material : 5.1.1 angular/cli: "~1.7.3" bootstrap: "~4.0.0" Encountering an error while running ng serve: ERROR in ./node_modules/raw-loader!./node_modules/postcss-loader?? embedded!./nod ...

The axios GET request failed to return a defined value

My current issue involves making a get request using the following code snippet: router.get('/marketUpdates',((request, response) => { console.log("market updates"); var data: Order[] axios.get('http://localhost:8082/marketUpdates& ...

Deploying an Angular-cli project to Digital Ocean

I am encountering an issue while trying to run my Angular 2 app on Digital Ocean. Despite successfully deploying my app on a cloud server, I am unable to connect to it on the specified port as the server does not respond. This is puzzling me as I have be ...

The Angular Material Stepper seems to have a glitch where calling the next() function does not work until I manually click

Currently, I am in the process of developing an Electron app using Angular 7 and Angular Material. Within my application, I have implemented a Stepper component where the second step involves making a call to the Electron main process to prompt the user t ...

Ways to fetch information from NGRX store in a linear manner

Struggling to handle NGRX's data access patterns effectively. Currently, I am retrieving data from my NGRX store in the following manner: logBooksAndAuthors() { const books$ = this.store.select(store => store.books); const authors$ = this.s ...

Steps for synchronously making multiple http calls at various levels in Angular 2 using RxJS

Currently, I am facing a challenge in Angular 2 where I need to make multiple HTTP calls synchronously at different levels using RxJS. Specifically, I have a resolver service that handles 5 API calls - a, b, c, d, and e. The order of execution I require i ...

When trying to access the "form" property of a form ElementRef, TypeScript throws an error

I've encountered an issue with accessing the validity of a form in my template: <form #heroForm="ngForm" (ngSubmit)="onSubmit()"> After adding it as a ViewChild in the controller: @ViewChild('heroForm') heroForm: ElementRef; Trying ...

Setting a default value dynamically in a `select` control can be done by using JavaScript to

Upon subscribing to the HTTP server for data retrieval, my select control in Angular framework gets loaded with the received data. My objective is to set a default value that comprises three values from the server object separated by slashes ("/"), which r ...

Fulfill the promise to retrieve the value contained within

Is there a way to use TypeScript to call the Wikipedia API for retrieving a random page title and save it in a variable for later use? I am struggling with resolving promises as I keep getting ZoneAwarePromise returned. I'm new to both promises and Ty ...

Steps to utilize the POST method with Angular, NodeJs/ExpressJs, and MySQL:

I am facing an issue with my Angular project where the GET method works fine, but when I try to call the POST method it seems like the POST function in Node.js is not getting called. Can someone help me figure out what I am doing wrong? Below are the snip ...

Setting the TypeScript version while initializing CDK

When creating a new CDK app in typescript, I typically use the following command: npx --yes <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d9babdb299e8f7e8eae1f7eb">[email protected]</a> init app --language typesc ...

Implementing Constants in Angular 2: Best Practices

Within my Angular 2 project, I have a crucial object known as translation that stores various strings utilized in multiple forms. This global configuration appears as follows: public translator = { 'performance_standard_time_deviation&apo ...

Placing images inside a div causes them to vanish

I encountered a strange issue where the images I added to a background disappeared. .Background1{ position:relative; top:0%; left:0%; height:100%; width:100%; content:url("/assets/backgroundlayer1.jpg") } .Background2{ posi ...

Filter the output from a function that has the ability to produce a Promise returning a boolean value or a

I can't help but wonder if anyone has encountered this issue before. Prior to this, my EventHandler structure looked like: export interface EventHandler { name: string; canHandleEvent(event: EventEntity): boolean; handleEvent(event: EventEntity ...

Error in Typescript: The type 'Element' does not have a property named 'contains'

Hey there, I'm currently listening for a focus event on an HTML dialog and attempting to validate if the currently focused element is part of my "dialog" class. Check out the code snippet below: $(document).ready(() => { document.addEventListe ...

The issue encountered is when the data from the Angular form in the login.component.html file fails to be

I am struggling with a basic login form in my Angular project. Whenever I try to submit the form data to login.components.ts, it appears empty. Here is my login.component.html: <mat-spinner *ngIf="isLoading"></mat-spinner> & ...

Angular 2 Array Filtering: Mastering the Art

Welcome! I'm a beginner in software development and currently diving into frontend development using Angular 2. My goal is to create a checkbox filter array that will return the selected values upon submission. Below is my code snippet: I've d ...

Combining HTTPHandler Observable with another in HTTPInterceptor (Angular 8)

In our Angular 8 project, we have set up our API so that the response includes both a "data" attribute and an "errors" attribute. It's possible for there to be data as well as errors in the response, and we need access to both in the calling component ...