AngularJS - Optimizing Video Loading Time

My template is set up to load details via a JSON file, including a video embed. While everything from the JSON files is working perfectly, I'm encountering an issue where the same video appears on every item. Is there a way to assign individual videos to each JSON file?

Below is the template for reference:

<div class="container" ng-repeat="guide in guides">
<div class="row">
<div class="col-md-12">
    <br/>
    <p><a ng-href="#/"><span class="glyphicon glyphicon-home"></span> Back to Guide List</a></p>
    <h1><span class="glyphicon glyphicon-play-circle"></span> Watch {{ guide.title }}</h1>

    <span>{{ guide.info }}</span><br/><br/>

</div>

<div class="col-md-12">    
    <video video="marvel">
    </video><!--This is the bit I'm having an issue with -->
</div>

<div class="col-md-6">
    <h3><span class="glyphicon glyphicon-education"></span> Background to {{ guide.title }}</h3>
    <span>{{ guide.background }}</span><br/><br/>
</div>
<div class="col-md-6">

    <h3><span class="glyphicon glyphicon-save"></span> Downloads for {{ guide.title }}</h3><br/>

                <a ng-href="{{ guide.pdf }}" target="_blank"><span class="glyphicon glyphicon-floppy-save"></span> Download Help Guide PDF</a><br/><br/>
                <a ng-href="{{ guide.video }}" target="_blank"><span class="glyphicon glyphicon-floppy-save"></span> Download Video</a>
    </div>

</div>
</div>

I'm facing issues binding data into the video tag (which is a directive I've created) - so I'm seeking suggestions or solutions.

Any help would be greatly appreciated.

Answer №1

To enhance your understanding, consider mentioning a new video in every repetition :-)

<div class="col-md-12">    
    <video src="{{guide.my_video_uri}}">
    </video>
</div>

If src=".." is not functioning, experiment with ng-src="..".

Answer №2

I appreciate the recommendation. I actually attempted this suggestion - the video tag can be a bit confusing; it is actually a custom directive called "video".

<video video="{{ guide.video }}">
</video>

However, when trying this, an error pops up: Cannot GET /%7B%7B%20videoUrl%20%7D%7D

Answer №3

This particular directive is designed to handle the embedding of YouTube videos, which are currently being used for testing purposes. Originally, the plan was to modify the trustAsResourceUrl function to accommodate a different type of embed in the future. Below is the code snippet for the directive (note that I have renamed the tag from 'video' to 'video-player')

guideApp.directive('videoPlayer', function ($sce) {

'use strict';

return {

    restrict: 'E',
    scope: { video: '=' },
    replace: true,
    template: '<div class="embed-responsive embed-responsive-16by9"><iframe class="embed-responsive-item" width="100%" height="100%" src="{{ videoUrl }}" frameborder="0" allowfullscreen></iframe></div>',
    link: function (scope) {
        scope.$watch('videoPlayer', function (videoLink) {
            if (videoLink) {
                scope.videoUrl = $sce.trustAsResourceUrl("https://www.youtube.com/embed/" + videoLink);
            }

        });

    }
};

});

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

What are some tips for keeping the bootstrap datepicker constantly visible?

Description I have successfully implemented the use of an 'input type=date' as a datepicker within bootstrap 5.3, allowing users to select dates for data viewing. However, the issue I am facing is that the datepicker is only visible upon clicki ...

I'm experiencing an issue with my dropdownlist not triggering the onchange event in AngularJS

I am a beginner in the world of AngularJS and I am trying to extract the values OnChange from a dropdown list. Here is the code that I have experimented with: <div> <select ng-controller="UserSelection as User" ng-model="User.UserSelected" n ...

"Optimizing Long Polling for Maximum Efficiency: Tips for utilizing php, Jquery

Hey everyone, I'm looking to implement real-time flash message notifications for users when they receive a new private message in their inbox. What is the most effective way to achieve this using technologies like PHP 5.3, jQuery, and JSON? I prefer ...

Firestore information does not appear visible

I encountered an issue with my custom hook where I am fetching images from a Firestore collection. Everything was working smoothly until I attempted to retrieve the metadata of the images as well. The problem arose when I included the getMetaData function, ...

Utilizing vue.js 3 to implement dual @click events on a single HTML element

I need to assign 2 mouse click events to a div element. One should be triggered by holding down the shift key while clicking, and the other by a regular click, like this: <div @click.shift="aaa()" @click="bbb()">...</div> T ...

What are the steps to implementing partial page functionality with the $http service in Angular?

Could someone assist me with executing an operation once a partial page has been successfully loaded using the $http service in Angular? The operation involves checking a checkbox based on the scope value. I have included the source code below: Here i ...

Divide the strings within an array

When working with nodejs, I utilize walksync to obtain an array as shown below: var paths = ['Essential Classes.jade' , 'introduction.jade'] These are the filenames contained within a folder. The objective is to extract only the filen ...

I am wondering if it is feasible for a POST route to invoke another POST route and retrieve the response ('res') from the second POST in Express using Node.js

Currently, I have a POST route that triggers a function: router.route('/generateSeed').post(function(req,res){ generate_seed(res) }); UPDATE: Here is the genrate_seed() function function generate_seed(res) { var new_seed = lightwallet. ...

Importing a Javascript file into an Angular project

I am currently working on an Angular application where routes are redirected to specific HTML pages. However, I am unsure about how to include related JavaScript files along with this redirection process. For instance, when a user clicks on a link that lo ...

JQuery - Issue: Invalid syntax detected in the expression: #

I'm facing an issue with some tabs inside an accordion that don't seem to be functioning properly. The console is showing the following error: Error: Syntax error, unrecognized expression: # Despite searching for a solution online, I can&apos ...

Utilizing Newtonsoft Json.NET to extract and set only the values from a Json string using the

Is it possible to selectively assign values from a Json string using the Newtonsoft Json.NET deserializer, even if they are default or null values? In the scenario described below, I am trying to identify values that are included in the _values dictionary ...

"Transformed JSON data into state for React JS Components using .map method

I've been working on setting the response of my 'apiRequest' into the Characters component's state. I've managed to log the returned JSON, but I'm struggling with how to use .map to set response.results into State. If anyone ...

Is it possible to utilize a variable from a Higher Order Function within a different generation function?

I am facing a dilemma with the need to utilize email = user.email in newcomment['comments/'+id] = {id,comment,email,date}. However, I am unable to incorporate email = yield user.email or yield auth.onAuthStateChanged(user => {email = user.em ...

Failed network request in my ReactJS project under the "Auth/network-request-failed" error code

I'm currently working on a project focused on learning to use react-router-dom and firebase authentication for user sign-in and sign-up. However, I've run into an issue where I keep getting a FirebaseError: "Firebase: Error (auth/network-request- ...

When making an AJAX request to an ASP.NET web method, strange characters are appended to the end of the response text. This issue seems

I need assistance with the following code: $.ajax({ type: 'POST', contentType: 'application/json; charset=utf-8', url: location, data: JSON.stringify(ajaxData), dataType: 'xml', success: ca ...

Incorporate a new class into the direct parent element using Angular

I am facing a scenario where an element is dynamically assigned a class. My goal is to append a new class to its parent element only if the child element has a specific class. <a [ngclass]="addClassHere"> //need to add class here if child h ...

The most effective method for verifying a user's login status using node.js and express and updating the client-side HTML

For my web application, I am using node.js and express along with sessions in mongoDB to handle server side code like this: exports.home = function(req, res){ if(req.session.userEnabled){ console.log("logged"); res.render('home', { title ...

What is the most efficient method for exporting Express route functions for promise chaining?

Currently, I am in the process of refactoring an API route to utilize ES6 promises instead of callbacks, so as to avoid callback hell. Upon successful conversion to a promise chain, my intention was to extract the .then() functions into a separate file fo ...

Rotate the image as you swipe left or right with Angular's ng-swipe-left and ng-swipe-right features

I am currently utilizing angular's ng-swipe-left and ng-swipe-right to detect swipe events on touch devices. My goal is to rotate an image based on the speed and direction of the swipe while it is still in progress. However, I am facing a challenge as ...

Deleting a row from the table with a single click on the X icon

Is there a way to delete individual rows in a table by clicking on a close icon instead of removing all rows at once? Additionally, I am looking for a better method to display rows in a table. You can view my current implementation here: link -> jsfiddl ...