What are the steps to integrate Videogular into an Ionic 2/Angular 2 development project?

I'm in need of a functional example showcasing Videogular 2 within an Ionic 2 setup or perhaps even in a plain Angular 2 environment.

Despite trying various online examples, it appears that the documentation is either outdated or completely inaccurate.

For instance, the documentation claims that a basic player can be created with:

  <videogular vg-theme="config.theme">
    <vg-media vg-src="config.sources"
          vg-tracks="config.tracks">
    </vg-media>

    <vg-overlay-play></vg-overlay-play>
  </videogular>

This results in an error when implemented in Typescript:

Error: Uncaught (in promise): Error: Template parse errors:
'vg-media' is not a known element

I have managed some success by using a vg-player element instead of videogular along with a video tag inside. Although this approach works, it only displays the native player. Whenever I try to use Videogular tags within, it throws a similar error as mentioned above.

All components are correctly included in my app.module.ts file under the imports section.

Here's my complete controller code:

import { Component } from '@angular/core';
import { NavController, NavParams, ToastController, LoadingController } from 'ionic-angular';

import { VgAPI } from 'videogular2/core';
import { VgCoreModule } from 'videogular2/core';
import { VgControlsModule } from 'videogular2/controls';
import { VgOverlayPlayModule } from 'videogular2/overlay-play';

import { Level } from '../../providers/level';

@Component({
  selector: 'page-programme-overview',
  templateUrl: 'programme_overview.html'
})
export class ProgrammeOverviewPage {

  api: VgAPI;
  videos: any;
  config: any;

  constructor(
    public navCtrl: NavController,
    public toastCtrl: ToastController,
    private navParams: NavParams) {

    // Video sources
    this.videos = [
      {
        sources: [
          {src: "http://static.videogular.com/assets/videos/videogular.mp4", type: "video/mp4"},
          {src: "http://static.videogular.com/assets/videos/videogular.webm", type: "video/webm"},
          {src: "http://static.videogular.com/assets/videos/videogular.ogg", type: "video/ogg"}
        ]
      },
      {
        sources: [
          {src: "http://static.videogular.com/assets/videos/big_buck_bunny_720p_h264.mov", type: "video/mp4"},
          {src: "http://static.videogular.com/assets/videos/big_buck_bunny_720p_stereo.ogg", type: "video/ogg"}
        ]
      } 
    ];

    this.config = {
      preload: "none",
      autoHide: false,
      autoHideTime: 3000,
      autoPlay: false,
      sources: this.videos[0].sources,
      theme: {
        url: "https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a9dfc0cdcc...">[email protected]</a>/dist/themes/default/videogular.css"
      },
      plugins: {
        poster: "http://www.videogular.com/assets/images/videogular.png"
      }
    };


  }

  // Play function
  onPlayerReady(api: VgAPI) {
    this.api = api;
    this.api.play();
  }

}

And here's my full HTML code:

<ion-header>
  <ion-navbar>
    <ion-title>Video</ion-title>
  </ion-navbar>
</ion-header>

<ion-content>

  <videogular vg-theme="config.theme">
    <vg-media vg-src="config.sources"
          vg-tracks="config.tracks">
    </vg-media>

    <vg-overlay-play></vg-overlay-play>
  </videogular>

</ion-content>

Any assistance would be highly appreciated. At this stage, I'm contemplating alternative video solutions, although I prefer to continue working with Videogular since it seems like a promising solution once operational.

Answer №1

If you opt for lazy loading, there is no need to import the modules in your app.module.ts. Instead, you can simply lazy load them in the page module ts

...
import { NgModule } from '@angular/core';
import { IonicPageModule } from 'ionic-angular';
import { VgCoreModule } from 'videogular2/core';
import { VgControlsModule } from 'videogular2/controls';
import { VgOverlayPlayModule } from 'videogular2/overlay-play';
import { VgBufferingModule } from 'videogular2/buffering';
{ VgAPI } from 'videogular2/core';
...

Once you have installed videogular via npm, if you are using lazy loading (which I assume you are), remember to import these modules from videogular2 in your page.module.ts

imports: [
    ...
    VgCoreModule,
    VgControlsModule,
    VgOverlayPlayModule,
    VgBufferingModule
],
providers:[
  VgAPI
]

VgAPI serves as the core API for most controls

In your HTML file

<vg-player (onPlayerReady)="onPlayerReady($event)">
   <vg-overlay-play></vg-overlay-play>
   <vg-buffering></vg-buffering>
   <vg-scrub-bar>
      <vg-scrub-bar-current-time></vg-scrub-bar-current-time>
      <vg-scrub-bar-buffering-time></vg-scrub-bar-buffering-time>
   </vg-scrub-bar>
   <vg-controls>
      <vg-play-pause></vg-play-pause>
      <vg-playback-button></vg-playback-button>
      <vg-time-display vgProperty="current" vgFormat="mm:ss"></vg-time-display>
      <vg-time-display vgProperty="total" vgFormat="mm:ss"></vg-time-display>
      <vg-track-selector></vg-track-selector>
      <vg-volume></vg-volume>
   </vg-controls>
   <video #media
   [vgMedia]="media"
   [src]="currentItem.src"
   id="singleVideo"
   preload="auto"
   crossorigin>
   </video>
</vg-player>

In your component.ts file

import {VgAPI } from 'videogular2/core';

export class MyPage{

api:VgAPI;

onPlayerReady(api: VgAPI) {
  this.api = api;
 }
}

Refer to their documentation on their website

Answer №2

I have successfully integrated Videogular2 into my Ionic2 project and so far, I am enjoying working with it. It seems like you may have mixed up Videogular(1) with Videogular2 in your code.

<videogular> is a component from the vg1 library (located at )

The repository for Videogular2 can be found here: https://github.com/videogular/videogular2. Make sure to refer to the documentation linked in the Readme file of the repository.

By following the Getting Started guide in the provided documentation, you will quickly understand the differences between Videogular1 and Videogular2, helping you avoid confusion when referring to online resources related to v1. I hope this information helps you!

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

Custom ID in Firebase Firestore is not generating a new document even after successfully creating a new user

In my Vue App, I designed a registration form to automatically create a Firestore document linked to the User UID with a unique document ID. Although the user creation process is successful, the document creation fails without showing any errors in the c ...

Tips for assigning a value to a data property within a different Vue component

I am faced with a situation where I have two Vue components. The first one triggers the opening of a modal, while the second one serves as the content within that modal in the form of a table and a brief form. Upon completing the form, my goal is to click ...

Unable to amend or remove fields within a JSON object

Typically, my process would include the following steps: var res = {}; res = { _id: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="5327362027132736202736217d303c3e">[email protected]</a>', ...

When executing npm run build, the fonts are not displayed properly in Vite

I'm running 'npm run build' to compile my project, and then I use the 'npm run preview' command to view it. However, some images that I've set as background images in my SCSS file are not showing up. The same issue occurs with ...

Navigating through elements with a pause

Currently, I am working on a solution to iterate through a series of divs and hide the currently displayed one, then after a 6-second delay, display the next one in sequence. Although my current implementation works, I find it to be inefficient and prone ...

Guide on serializing an object containing a file attribute

I'm currently working on creating a small online catalog that showcases various housing projects and allows users to download related documents. The data structure I am using is fairly straightforward: each project has its own set of properties and a ...

How can I delay the loading of a lazy loaded module in Angular until certain data is resolved from an API call?

How can I preload data before loading a lazy module in Angular? I attempted using app_initializer, but it didn't work due to an existing app_initializer in AppModule. Is there a different approach to achieve this? ...

What steps should I take to create an in-site product filtering system with multiple dropdowns by utilizing a JSON file?

I have created an in-site redirect tool for our E-Commerce platform by utilizing resources from this website. I am looking to enhance the functionality of these in-site redirects by implementing a JSON file that contains options tailored to our existing li ...

Efficient Ways to Store Text and Images in Vue.js

I have developed a tool that enables users to upload an image and overlay custom text on it, which can be viewed and edited in the browser. My query is whether it is feasible to save the combined image and text as separate files (e.g., jpg/png) using VueJS ...

Choosing multiple options from a list in asp.net with a drop-down menu

Here is the code for a default dropdown single select list without checkboxes or buttons in the WebAPP.NET framework: <asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:ODWConnection ...

Is React Portal truly necessary?

While I understand the concept of using react portal to add a component outside the rendered hierarchy tree in React, such as when we want to display a Model component above everything else on the page, I find myself questioning why not simply place this ...

Initiate search on new page with form action

I am encountering an issue with my search field setup in index.php. It seems that when I navigate through the pagination links to pagination.php, the form data is getting reset. <?php include('db.php'); if (isset($_GET["page"])) { $pa ...

How to retrieve an array of objects using Angular 2 service?

I am facing an issue with my Angular 2 service component. It is responsible for populating an array of objects, and I need to access this array from other components in the program. However, the getUsers() method always returns null as shown in the code sn ...

What is the best approach to implement a gradual loading of data in a FlatList in React Native

I am facing an issue with my flatlist where the renderItem function does not render data properly from my custom backend when the internet connection is slow or if I reload too many times. This results in either the data not appearing on the screen or the ...

Redirecting based on GeoIP location after the DOM has completely loaded

Below is a JavaScript snippet that redirects based on GEOIP : <script type="text/javascript"> // Function to call FreeGeoIP after page load function newyorkGeoIP() { var script = document.createElement('script' ...

Retrieve the width and height of an image

Does anyone know how to retrieve the dimensions of an image using JavaScript or jQuery when no styles are defined for it (resulting in jQuery's css() returning 0)? I suspect that the issue may arise from loading the image with jQuery right before att ...

Creating a 10-digit unique value can be achieved with either meteor or JavaScript

I am in need of generating 10 character unique codes, containing both letters and digits, to be utilized for system generated gift vouchers. Currently, the code I am using includes 13 numbers. var today = new Date(); Number(today); Is there a different m ...

Fix a carousel layout problem

I've made changes to an HTML-PHP module to display portfolio images as a carousel, and I'm using the same module on this website too. However, I've encountered an issue with duplicate content and the previous-next navigation buttons. Can so ...

Measuring the size of each item within a given array

In my quest to determine the length of each word in a lengthy text, I am seeking assistance. I aim to return an array containing the length of every word at the conclusion of this function. My current approach involves utilizing two loops - one to separat ...

methods for retrieving data from a Laravel controller within an imported JavaScript file

My current approach involves using ajax to update a table based on the user's input. $('#user').change(function(){ var user= $("#user").val(); if (user !='None'){ $.ajax({ type: "GET", url: '/getUserAccounts/&a ...