Multiple Youtube Chromeless Players on a Single Page - youtube

I'm trying to embed multiple youtube videos in a single web page using the chromeless player. This isn't multiple videos in the same player, this is multiple players on a single page.
Here is an example. (only the last video shows up):
<div>
<div id="ytapiplayer">
You need Flash player 9+ and JavaScript enabled to view this video.
</div>
<script type="text/javascript">
var params = { allowScriptAccess: "always" };
var atts = { id: "myytplayer" };
swfobject.embedSWF("http://www.youtube.com/apiplayer?enablejsapi=1&version=3&playerapiid=1234","ytapiplayer", "499", "281", "9", null, null, params, atts);
function onYouTubePlayerReady(playerId) {
ytplayer = document.getElementById("myytplayer");
ytplayer.cueVideoById("Zhawgd0REhA");
}
</script>
</div>
<div>
<div id="ytapiplayer2">
You need Flash player 9+ and JavaScript enabled to view this video.
</div>
<script type="text/javascript">
var params = { allowScriptAccess: "always" };
var atts = { id: "myytplayer2" };
swfobject.embedSWF("http://www.youtube.com/apiplayer?enablejsapi=1&version=3&playerapiid=4321","ytapiplayer2", "499", "281", "9", null, null, params, atts);
function onYouTubePlayerReady(playerId) {
ytplayer2 = document.getElementById("myytplayer2");
ytplayer2.cueVideoById("qkAn_qJdgBs");
}
</script>
</div>
Any help would be greatly appreciated.

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js"></script>
<div>
<div id="ytapiplayer">
You need Flash player 9+ and JavaScript enabled to view this video.
</div>
<script type="text/javascript">
var params = { allowScriptAccess: "always" };
var atts = { id: "myytplayer" };
swfobject.embedSWF("http://www.youtube.com/apiplayer?enablejsapi=1&version=3&playerapiid=player1","ytapiplayer", "499", "281", "9", null, null, params, atts);
function onYouTubePlayerReady(playerId) {
if(playerId == "player1"){
ytplayer = document.getElementById("myytplayer");
ytplayer.cueVideoById("H9v3eky91no");
}else{
if(playerId == "player2"){
ytplayer2 = document.getElementById("myytplayer2");
ytplayer2.cueVideoById("EGnwL0ganu0");
}
}
}
</script>
</div>
<div>
<div id="ytapiplayer2">
You need Flash player 9+ and JavaScript enabled to view this video.
</div>
<script type="text/javascript">
var params = { allowScriptAccess: "always" };
var atts = { id: "myytplayer2" };
swfobject.embedSWF("http://www.youtube.com/apiplayer?enablejsapi=1&version=3&playerapiid=player2","ytapiplayer2", "499", "281", "9", null, null, params, atts);
</script>
</div>

A little late maybe, but i was searching for the solution and i found this page.
Your code do not work now, maybe it did before but not now.
I was frustrated and now i finally made it work.
Here is a working code on today's youtube javascript api with chromeless player.
I added some custom error handling also - Showing a div instead of alert if something is wrong. Example. Embedding Disabled or wrong movieID. And 2 play buttons so you can use same functionality if you want to show a preview image before play. (Nice for Slideshow's).
Working code July 31, 2011.
<script src="http://www.google.com/jsapi" type="text/javascript"></script>
<script type="text/javascript">
google.load("swfobject", "2.1");
</script>
<script type="text/javascript">
function updateHTML(elmId, value) { document.getElementById(elmId).innerHTML = value;}
function onPlayerError(errorCode) {if (errorCode == 150) { document.getElementById("embed_disabled").style.display = 'block'; }else { if (errorCode == 2) {document.getElementById("notfound").style.display = 'block';}}}
function onYouTubePlayerReady(playerId) {
if (playerId == "player1") {
ytplayer = document.getElementById("ytPlayer");
ytplayer.addEventListener("onError", "onPlayerError");
}
else if (playerId == "player2") {
ytplayer2 = document.getElementById("ytPlayer2");
ytplayer2.addEventListener("onError", "onPlayerError");
}
}
function playVideo16() { if (ytplayer) {ytplayer.playVideo();}}
function pauseVideo16() { if (ytplayer) { ytplayer.pauseVideo(); } }
function playVideo17() { if (ytplayer2) { ytplayer2.playVideo(); } }
function pauseVideo17() { if (ytplayer2) { ytplayer2.pauseVideo(); } }
function loadPlayer() {
var params = { allowScriptAccess: "always" };
var atts = { id: "ytPlayer" };
swfobject.embedSWF("http://www.youtube.com/apiplayer?video_id=4PspF_GA-9U&version=3&enablejsapi=1&playerapiid=player1&showinfo=0&controls=0&iv_load_policy=3&modestbranding=1&rel=0", "videoDiv", "480", "295", "10", null, null, params, atts);
var params = { allowScriptAccess: "always" };
var atts = { id: "ytPlayer2" };
swfobject.embedSWF("http://www.youtube.com/apiplayer?video_id=G68fHZig9nA&version=3&enablejsapi=1&playerapiid=player2&showinfo=0&controls=0&iv_load_policy=3&modestbranding=1&rel=0", "videoDiv2", "480", "295", "10", null, null, params, atts);
}
function _run() { loadPlayer();}
google.setOnLoadCallback(_run);
</script>
<div id="embed_disabled" style="color:#fff;position:absolute;background:#000;width:959px;height:5500px;z-index:100000;display:none">Embed disabled</div>
<div id="notfound" style="color:#fff;position:absolute;background:#000;width:959px;height:5500px;z-index:100000;display:none">Movie not found</div>
<div id="preview_videoDiv" onclick="this.style.display='none';playVideo16()" style="cursor:pointer;color:#fff;position:absolute;background:#000;width:480px;height:295px;z-index:100000;text-align:center;"><p style="padding-top:100px">Start movie</p></div>
<div id="videoDiv">Loading...</div>
<div style="clear:both;">Play | Pause</div>
<div id="preview_videoDiv2" onclick="this.style.display='none';playVideo17()" style="cursor:pointer;color:#fff;position:absolute;background:#000;width:480px;height:295px;z-index:100000;text-align:center;"><p style="padding-top:100px">Start movie</p></div>
<div id="videoDiv2" style="clear:both;">Loading...</div>
<div style="clear:both;">Play | Pause</div>

fixed:
<script type="text/javascript">
var params = { allowScriptAccess: "always" };
var atts = { id: "myytplayer" };
swfobject.embedSWF("http://www.youtube.com/apiplayer?enablejsapi=1&version=3&playerapiid=player1","ytapiplayer", "499", "281", "9", null, null, params, atts);
function onYouTubePlayerReady(playerId) {
if(playerId == "player1"){
ytplayer = document.getElementById("myytplayer");
ytplayer.cueVideoById("H9v3eky91no");
}else{
if(playerId == "player2"){
ytplayer2 = document.getElementById("myytplayer2");
ytplayer2.cueVideoById("EGnwL0ganu0");
}
}
}
</script>
</div>
<div>
<div id="ytapiplayer2">
You need Flash player 9+ and JavaScript enabled to view this video.
</div>
<script type="text/javascript">
var params = { allowScriptAccess: "always" };
var atts = { id: "myytplayer2" };
swfobject.embedSWF("http://www.youtube.com/apiplayer?enablejsapi=1&version=3&playerapiid=player2","ytapiplayer2", "499", "281", "9", null, null, params, atts);
</script>
</div>

Related

give default value to md-autocomplete

How to pass default value in md-autocomplete?
Image 1 : HTML code
Image 2 : JS code
Image 3 : Output
As you can see, I am not getting any default country as output. Is there any way to do that?
Assign yr SearchText the default value & selectedItem the object.
$scope.local ={
...
searchText : 'Default Value',
selectedItem : 'Default object'
...
}
I write small codepen with autocomplete and default value.
What you must do:
Init main model.
Define model field, used in autocomplete md-selected-item property.
Define callback for loading autocomplete items.
Before save main model extract id (or other field) from associated field.
Main error in your code here:
$scope.local = {
...
selectedItem: 1, // Must be object, but not integer
...
}
(function(A) {
"use strict";
var app = A.module('app', ['ngMaterial']);
function main(
$q,
$scope,
$timeout
) {
$timeout(function() {
$scope.user = {
firstname: "Maxim",
lastname: "Dunaevsky",
group: {
id: 1,
title: "Administrator"
}
};
}, 500);
$scope.loadGroups = function(filterText) {
var d = $q.defer(),
allItems = [{
id: 1,
title: 'Administrator'
}, {
id: 2,
title: 'Manager'
}, {
id: 3,
title: 'Moderator'
}, {
id: 4,
title: 'VIP-User'
}, {
id: 5,
title: 'Standard user'
}];
$timeout(function() {
var items = [];
A.forEach(allItems, function(item) {
if (item.title.indexOf(filterText) > -1) {
items.push(item);
}
});
d.resolve(items);
}, 1000);
return d.promise;
};
}
main.$inject = [
'$q',
'$scope',
'$timeout'
];
app.controller('Main', main);
}(this.angular));
<head>
<link href="https://cdnjs.cloudflare.com/ajax/libs/angular-material/0.11.0/angular-material.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.6/angular.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.6/angular-aria.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.6/angular-animate.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-material/0.11.0/angular-material.min.js"></script>
</head>
<body ng-app="app" flex layout="column" layout-margin ng-controller="Main">
<md-content layout="column" class="md-whiteframe-z1" layout-margin>
<md-toolbar>
<div class="md-toolbar-tools">
<h3>Form</h3>
</div>
</md-toolbar>
<md-content class="md-whiteframe-z1">
<div class="md-padding">
<md-input-container>
<label for="firstname">First name</label>
<input type="text" name="firstname" ng-model="user.firstname" />
</md-input-container>
<md-input-container>
<label for="lastname">Last name</label>
<input type="text" name="lastname" ng-model="user.lastname" />
</md-input-container>
<md-autocomplete md-selected-item="user.group" md-items="item in loadGroups(filterText)" md-item-text="item.title" md-search-text="filterText">
<md-item-template>{{ item.title }}</md-item-template>
<md-not-found>No items.</md-not-found>
</md-autocomplete>
</div>
</md-content>
</md-content>
<md-content class="md-whiteframe-z1" layout-margin>
<md-toolbar>
<div class="md-toolbar-tools">
<h3>Model as JSON</h3>
</div>
</md-toolbar>
<md-content class="md-padding">
<p>
{{ user | json }}
</p>
</md-content>
</md-content>
</body>
I know this is an old question, but some people may benefit from my solution. I struggled with the problem of the model for the auto-complete being asynchronous and having my autocompletes as part of an ng-repeat. Many of the solutions to this problem found on the web have only a single auto complete and static data.
My solution was to add another directive to the autocomplete with a watch on the variable that I want to set as default for the auto complete.
in my template:
<md-autocomplete initscope='{{quote["Scope"+i]}}' ng-repeat='i in [1,2,3,4,5,6,7,8]'
class='m-1'
md-selected-item="ScopeSelected"
md-clear-button="true"
md-dropdown-position="top"
md-search-text="pScopeSearch"
md-selected-item-change='selectPScope(item.label,i)'
md-items="item in scopePSearch(pScopeSearch,i)"
md-item-text="item.label"
placeholder="Plowing Scope {{i}}"
md-min-length="3"
md-menu-class="autocomplete-custom-template"
>
then in my module:
Details.directive('initscope', function () {
return function (scope, element, attrs) {
scope.$watch(function (){
return attrs.initscope;
}, function (value, oldValue) {
//console.log(attrs.initscope)
if(oldValue=="" && value!="" && !scope.initialized){
//console.log(attrs.initscope);
var item = {id:0, order:0,label:attrs.initscope?attrs.initscope:"" }
scope.ScopeSelected = item;
scope.initialized = true;
}
});
};
});
this checks for changes to the quote["Scope"+i] (because initially it would be null) and creates an initial selected item and sets the autocompletes' selected item to that object. Then it sets an initialized value to true so that this never happens again.
I used timeout to do this.
$timeout(function() {
$scope.local = {selectedItem : 1}
}, 2000);

The Entity is not getting loaded in Easy Query builder in MVC Application

I have added the Easy Query Builder in to my MVC project by using the demo application of Easy Query Builder and i have added the .css and .js file according to the demo project. while executing
the entity is not getting loaded and the constructor and the getModel() is not been invoked. The EQ.Client is undefined once the page is loaded
Here is my code.
EasyQuery.cshtml( view )
<script type="text/javascript">
window.easyQuerySettings = {
serviceUrl: "/EasyQuery",
modelName: "NWindSQL",
entitiesPanel: { showCheckboxes: true },
columnsPanel: {
allowAggrColumns: true,
attrElementFormat: "{entity} {attr}",
showColumnCaptions: true,
adjustEntitiesMenuHeight: false,
menuOptions: {
showSearchBoxAfter: 30,
activateOnMouseOver: true
}
},
queryPanel: {
showPoweredBy: false,
alwaysShowButtonsInPredicates: false,
adjustEntitiesMenuHeight: false,
menuOptions: {
showSearchBoxAfter: 20,
activateOnMouseOver: true
}
},
syncQueryOptions: {
sqlOptions: { SelectDistinct: true }
},
};
function getPrefix() {
var res = window.location.pathname;
if (res.charAt(res.length - 1) !== '/')
res = res + '/';
return res;
}
</script>
<div class="entities-panel-container">
<div id="EntitiesPanel"></div>
</div>
<div class="columns-panel-container">
<div id="ColumnsPanel"></div>
</div>
<div class="query-panel-container">
<div id="QueryPanel"></div>
</div>
<script type="text/javascript">
**$(function () {
var query = EQ.client.getQuery();
EQ.client.loadModel({ modelName: "Model1" });
});**
</script>
in the EasyQuerycontroller.cs
public class **EasyQueryController** : Controller
{
private EqServiceProviderDb eqService;
public **EasyQueryController()**
{
eqService = new EqServiceProviderDb();
eqService.SessionGetter = key => Session[key];
eqService.SessionSetter = (key, value) => Session[key] = value;
eqService.StoreQueryInSession = true;
eqService.Formats.SetDefaultFormats(FormatType.MsSqlServer);
eqService.Formats.UseSchema = false;
string dataPath = System.Web.HttpContext.Current.Server.MapPath("~/App_Data");
eqService.DataPath = dataPath;
eqService.Connection = new SqlConnection("Data Source=" + System.IO.Path.Combine(dataPath, "Northwind.sdf"));
}
[HttpPost]
public ActionResult GetModel(string modelName)
{
var model = eqService.GetModel(modelName);
return Json(model.SaveToDictionary());
}
...
}
should i need to change some code or include some other feature to fill the EQ.Client element.?
I don't see where you actually include EasyQuery scripts on your view page.
There must be something like the following markup at the end (before closing "body" tag) of your view page:
<script src="http://cdn.korzh.com/eq/3.6.0/eq.all.min.js" type="text/javascript"></script>
<script src="http://cdn.korzh.com/eq/3.6.0/eq.view.basic.js" type="text/javascript"></script>

Why is the video not loading?How should I load and play a video on a chromeless player?

<html>
<body>
<div id="ytplayer_div1">You need Flash player 8 or higher to view this content.</div>
<script type='text/javascript' src='swfobject.js'> </script>
<script type='text/javascript'>
swfobject.embedSWF
(
'http://www.youtube.com/apiplayer?enablejsapi=1',
'ytplayer_div1',
'425',
'344',
'8',
null,
null,
{
allowScriptAccess: 'always',
allowFullScreen: 'true'
},
{
id: 'ytplayer_object'
}
);
var ytplayer = document.getElementById("ytplayer_div1");
ytplayer.loadVideoById("bHQqvYy5KYo", 5, "large");
</script>
</body>
</html>
From YouTube Javascript Player API: Getting Started,
When the player is ready, the API will call the onYouTubePlayerReady callback function.
Wrap
var ytplayer = document.getElementById("ytplayer_div1");
ytplayer.loadVideoById("bHQqvYy5KYo", 5, "large");
with
onYouTubePlayerReady = function() {
var ytplayer = document.getElementById("ytplayer_object");
ytplayer.loadVideoById("bHQqvYy5KYo", 5, "large");
}
Take note of document.getElementById("ytplayer_object"), where the id must equal the id attribute passed into swfobject.embedSWF here:
{
id: 'ytplayer_object'
}

Multiple ViewModels Knockout with JQuery

I Have this Fiddle
It is working perfectly in the fiddle, but as soon as i put everything in a ASP.NET MVC4 Application the second ViewModel is not loaded!
This normally is only when i add the following Script Tag to my Project
<script src="../../Scripts/jquery.mobile-1.2.0.js" type="text/javascript"></script>
Do i need some JQuery Functions to load the second ViewModel or what did i wrong? ;)
Here is my code:
<form action="" data-bind=" template:{ 'if': loginVM, data: loginVM }">
//SomeCode
</form>
<form action="" data-bind=" template:{ 'if': startVM, data: startVM}">
//Some Code
</form>
<script type="text/javascript">
var masterViewModel = {
loginVM: ko.observable(),
startVM: ko.observable(),
projektUnterbrechen: ko.observable(),
logout : ko.observable(),
projectStartVM: ko.observable()
};
var LoginVM = function () {
var self = this;
self.mandant = ko.observable();
self.user = ko.observable();
self.password = ko.observable();
self.showDetails = function () {
if ((self.user() == "Gregor") && (self.password() == "gregrech")) {
masterViewModel.loginVM(null);
masterViewModel.startVM(new StartVM());
**//alert(masterViewModel.startVM()!=null) //==True**
}
else {
alert("Username oder Passwort falsch");
}
};
};
var StartVM = function () {
self = this;
**//alert(masterViewModel.startVM()!=null) //==False**
//Um weiterzumachen muss man eingeloggt sein
self.favoriten = ko.observableArray([
{
projectName: "Favorit1"
},
{
projectName: "Favorit2"
},
{
projectName: "Favorit3"
}
]);
//Die zuletzt verwendeten Projekte
self.zuletzt = ko.observableArray([
{
lastProjName: "Zuletzt1"
},
{
lastProjName: "Zuletzt2"
},
{
lastProjName: "Zuletzt3"
}
]);
self.showStart = function (projectName, data, event) {
masterViewModel.projectStartVM(new ProjectStartVM(projectName));
masterViewModel.startVM(null);
};
};
masterViewModel.loginVM(new LoginVM());
$(document).on('pageinit', function () {
ko.applyBindings(masterViewModel);
});
</script>
Thank you for your answers
EDIT:
I found out, that i get different Values if i compare my masterViewModel.startVM()!= null even if it has to be the same!
Maybe this helps you!
Please look at the comments with "**" in my Code to understand what i mean
Try to load viewmodel in ready event not pageinit event.
$(document).ready(function () {
ko.applyBindings(masterViewModel);
});

How to Move code from jsfiddle to local system for testing

This similar to Question https://stackoverflow.com/questions/13693170/changed-version-of-knockout-js
I would like move the code from jsfiddle to local system for testing. The code works for adds, checked, delete. But, what it does not do is load the fake data from within the model.js. I have changed /echo/json. to local url. What else do I need to do? Using latest firefox.
model.js >>>>
$(document).ready(function() {
var fakeData = [{
"title": "Wire the money to Panama",
"isDone": true},
{
"title": "Get hair dye, beard trimmer, dark glasses and passport",
"isDone": false},
{
"title": "Book taxi to airport",
"isDone": false},
{
"title": "Arrange for someone to look after the cat",
"isDone": false}];
function Task(data) {
this.title = ko.observable(data.title);
this.isDone = ko.observable(data.isDone);
}
function TaskListViewModel() {
// Data
var self = this;
self.tasks = ko.observableArray([]);
self.newTaskText = ko.observable();
self.incompleteTasks = ko.computed(function() {
return ko.utils.arrayFilter(self.tasks(), function(task) { return !task.isDone() && !task._destroy });
});
// Operations
self.addTask = function() {
self.tasks.push(new Task({ title: this.newTaskText() }));
self.newTaskText("");
};
self.removeTask = function(task) { self.tasks.destroy(task) };
self.save = function() {
$.ajax("/ds", {
data: {
json: ko.toJSON({
tasks: this.tasks
})
},
type: "POST",
dataType: 'json',
success: function(result) {
alert(ko.toJSON(result))
}
});
};
//Load initial state from server, convert it to Task instances, then populate self.tasks
$.ajax("/ds", {
data: {
json: ko.toJSON(fakeData)
},
type: "POST",
dataType: 'json',
success: function(data) {
var mappedTasks = $.map(data, function(item) {
return new Task(item);
});
self.tasks(mappedTasks);
}
});
}
ko.applyBindings(new TaskListViewModel());
});
ds.html
<script type="text/javascript" src="static/js/jquery-1.6.3.min.js"></script>
<script type="text/javascript" src="static/js/knockout-2.0.0.js"></script>
<p>
<div class="codeRunner">
<h3>Tasks</h3>
<form data-bind="submit: addTask">
Add task: <input data-bind="value: newTaskText" placeholder="What needs to be done?" />
<button type="submit">Add</button>
</form>
<ul data-bind="foreach: tasks, visible: tasks().length > 0">
<li>
<input type="checkbox" data-bind="checked: isDone" />
<input data-bind="value: title, disable: isDone" />
Delete
</li>
</ul>
You have <b data-bind="text: incompleteTasks().length"> </b> incomplete task(s)
<span data-bind="visible: incompleteTasks().length == 0"> - it's beer time!</span>
<button data-bind="click: save">Save</button>
</div>
</p>
<script type="text/javascript" src="static/js/model.js" ></script>
The ajax requests in the fiddle are just mock requests to simulate real-world scenarios, they're not really necessary.. you can use that fake data without any ajax requests. For example change these parts:
self.save = function() {
alert(ko.toJSON({tasks: this.tasks}));
};
//Load initial state from server, convert it to Task instances, then populate self.tasks
var mappedTasks = $.map(fakeData, function(item) {
return new Task(item);
});
self.tasks(mappedTasks);
If you want to use ajax requests to get real data, you'll need to post the data in the format required by your own server API (i.e. not with that 'json' field in the data that is used in jsfiddle's json-echo service API)

Resources