-
youtube api closed captions
hello
i'm building a chromeless api for youtube videos
i want to force the subtitles to always show...using "cc_load_policy=1"
like this
var my_loader:Loader = new Loader();
my_loader.load(new URLRequest("http://www.youtube.com/apiplayer?version=3&cc_load_policy=1"));
it doesn't work....
can anyone help me please !
thank you
-
Designer, Programmer, Musician
I think you have to set the cc_load_policy=1, out of tha load script, in the script where the load finishes
my_loadercontentLoaderInfo.addEventListener(Event. COMPLETE, loaded);
}
function loaded(e:Event){
my_loader.cc_load_policy=1;
}
Something like that. What i want to say is, you have to call the cc_load_policy=1 when the video finishes loading. Try that! Good luck
Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries
-
Thank you very much for your help
I tried your suggestion unfortunately I still couldn't get it to work.
The only way I have gotten it to work is by embedding the video (rather than using a chromeless player),
If I use:
my_loader.load(new URLRequest("http://www.youtube.com/v/"Video ID"?version=3&cc_load_policy=1"));
instead of:
my_loader.load(new URLRequest("http://www.youtube.com/apiplayer?version=3&cc_load_policy=1"));
it loads with subtitles....however this causes further difficulties because then I can't load the next video.
I have 7 videos that I need to load at various starting points....
this is the complete script .....
var my_loader:Loader = new Loader();
my_loader.load(new URLRequest("http://www.youtube.com/v/"Video ID"?version=3&cc_load_policy=1"));
my_loader.contentLoaderInfo.addEventListener(Event .INIT, onLoaderInit);
function onLoaderInit(e:Event):void{
addChild(my_loader);
my_loader.x = 170;
my_loader.y = 50;
my_player = my_loader.content;
my_player.addEventListener("onReady", onPlayerReady);
}
function onPlayerReady(e:Event):void{
my_player.setSize(550,400);
my_player.loadVideoById("Video ID",46);
}
load_btn.addEventListener(MouseEvent.CLICK, loadNext);
function loadNext(e:MouseEvent):void {
my_player.loadVideoById("new Video ID", 12);
}
-
Designer, Programmer, Musician
Yeah, i forgot about the fact of the loading of youtube videos into flash. I've always used something like my_loader.load(new URLRequest("http://www.youtube.com/v/"Video ID"?) but i have one .fla that uses http://www.youtube.com/apiplayer?version=3 instead.
Maybe this script helps you:
PHP Code:
Security.allowDomain("www.youtube.com");
var my_player:Object
var my_loader:Loader = new Loader();
my_loader.load(new URLRequest("http://www.youtube.com/apiplayer?version=3"));
my_loader.contentLoaderInfo.addEventListener(Event.INIT, onLoaderInit);
function onLoaderInit(e:Event):void{
addChild(my_loader);
my_player = my_loader.content;
my_player.addEventListener("onReady", onPlayerReady);
}
function onPlayerReady(e:Event):void{
my_player.setSize(640,360);
my_player.cueVideoById("_OBlgSz8sSM",0);
}
_OBlgSz8sSM is the ID of the video.
Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries
-
thanks
do you have any idea how i could combine the loadNext button ......
load_btn.addEventListener(MouseEvent.CLICK, loadNext);
function loadNext(e:MouseEvent):void {
my_player.loadVideoById("new Video ID", 12);
}
with the embedded video ?? .....
my_loader.load(new URLRequest("http://www.youtube.com/v/"Video ID"?)
??
)
-
Designer, Programmer, Musician
Try this
PHP Code:
Security.allowDomain("www.youtube.com");
var my_player:Object;
var my_loader:Loader = new Loader();
function onLoaderInit(e:Event):void{ addChild(my_loader); my_player = my_loader.content; my_player.addEventListener("onReady", onPlayerReady); }
function onPlayerReady(e:Event):void{ my_player.setSize(640,360); my_player.loadVideoById("_OBlgSz8sSM",0); }
load_btn.addEventListener(MouseEvent.CLICK, loadNext); function loadNext(e:MouseEvent):void { my_loader.load(new URLRequest("http://www.youtube.com/apiplayer?version=3&cc_load_policy=1")); my_loader.contentLoaderInfo.addEventListener(Event.INIT, onLoaderInit); }
If that doesn't do what you want, then make this modification:
Security.allowDomain("www.youtube.com");
var my_player:Object;
var my_loader:Loader = new Loader();
function onLoaderInit(e:Event):void{
addChild(my_loader);
my_player = my_loader.content;
my_player.addEventListener("onReady", onPlayerReady);
}
function onPlayerReady(e:Event):void{
my_player.setSize(640,360);
my_player.loadVideoById("_OBlgSz8sSM",0);
my_player.cc_load_policy=1;
}
load_btn.addEventListener(MouseEvent.CLICK, loadNext);
function loadNext(e:MouseEvent):void {
my_loader.load(new URLRequest(" http://www.youtube.com/apiplayer?version=3"));
my_loader.contentLoaderInfo.addEventListener(Event .INIT, onLoaderInit);
}
Last edited by angelhdz; 02-07-2014 at 06:20 PM.
Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries
-
!! this is very helpful
that's nearly it. I'm now getting two videos loading, each showing subtitles
i had to change your code a bit, from chromeless to embedded:
The problem remaining, is that the previous video continues to run at the same time, after the second is loaded. I hear the audio from them both.
I can't seem to find a way to UNLOAD the previous my_loader.content .
how can the previous loader/video be unloaded or deleted ? do i remove the child ??
the script is below....perhaps i don't need a new player and a new loader with each button ??: !
Thank you
var my_player:Object;
var my_player2:Object;
var my_loader:Loader = new Loader();
var my_loader2:Loader = new Loader();
////////////////////////////////////////////////////////////////
load_btn.addEventListener(MouseEvent.CLICK, loadNext);
function loadNext(e:MouseEvent):void {
my_loader.load(new URLRequest("http://www.youtube.com/v/video ID 1?version=3&cc_load_policy=1"));
my_loader.contentLoaderInfo.addEventListener(Event .INIT, onLoaderInit);
//my_player.loadVideoById("video ID 1", 46);
}
function onLoaderInit(e:Event):void{
addChild(my_loader);
my_loader.x = 170;
my_loader.y = 50;
my_player = my_loader.content;
my_player.addEventListener("onReady", onPlayerReady);
}
function onPlayerReady(e:Event):void{
my_player.setSize(550,400);
my_player.loadVideoById("video ID 1",46);
}
////////////////////////////////////////////////////////////////
load_btn2.addEventListener(MouseEvent.CLICK, loadNext2);
function loadNext2(e:MouseEvent):void {
my_loader2.load(new URLRequest("http://www.youtube.com/v/video ID 2?version=3&cc_load_policy=1"));
my_loader2.contentLoaderInfo.addEventListener(Even t.INIT, onLoaderInit2);
//my_player.loadVideoById("video ID 2", 46);
}
function onLoaderInit2(e:Event):void{
//removeChild(my_loader);
addChild(my_loader2);
my_loader2.x = 170;
my_loader2.y = 50;
my_player2 = my_loader2.content;
my_player2.addEventListener("onReady", onPlayerReady2);
}
function onPlayerReady2(e:Event):void{
my_player2.setSize(550,400);
my_player2.loadVideoById("video ID 2",46);
}
///////////////////////////////////////////////////////////////////
-
.
Hi,
Try
PHP Code:
function onLoaderInit2(e:Event):void
{
while (my_player.numChildren > 0)
{
my_player.removeChildAt(0);
}
//removeChild(my_loader);
addChild(my_loader2);
my_loader2.x = 170;
my_loader2.y = 50;
my_player2 = my_loader2.content;
my_player2.addEventListener("onReady", onPlayerReady2);
}
-
Designer, Programmer, Musician
-
Originally Posted by angelhdz
Thanks fruitbeard! You saved me time
Thank you both
I think it's solved
the "removeChildAt" didn't seem to work 100%. The image disappeared but not the sound.
i added a pauseVideo() to shut it up !
for now then, i'm loading 2 vids, one after the other with the subtitles forced to appear, so thank you to you both for your kind help.
now i'm going to try and get the player stopping and starting 7 videos, so .... we will see what happens !!
Thanks again....below is what I've ended up with so far.
very best regards x
/////////////////////////////////////////////////////////////////
Security.allowDomain("www.youtube.com");
var my_player:Object;
var my_player2:Object;
var my_loader:Loader = new Loader();
var my_loader2:Loader = new Loader();
load_btn.addEventListener(MouseEvent.CLICK, loadNext);
function loadNext(e:MouseEvent):void {
my_loader.load(new URLRequest("http://www.youtube.com/v/video ID 1?version=3&cc_load_policy=1"));
my_loader.contentLoaderInfo.addEventListener(Event .INIT, onLoaderInit);
while (my_player2.numChildren > 0)
{
my_player2.removeChildAt(0);
my_player2.pauseVideo();
}
}
function onLoaderInit(e:Event):void{
addChild(my_loader);
my_loader.x = 170;
my_loader.y = 50;
my_player = my_loader.content;
my_player.addEventListener("onReady", onPlayerReady);
}
function onPlayerReady(e:Event):void{
my_player.setSize(550,400);
my_player.loadVideoById("video ID 1",46);
}
load_btn2.addEventListener(MouseEvent.CLICK, loadNext2);
function loadNext2(e:MouseEvent):void {
my_loader2.load(new URLRequest("http://www.youtube.com/v/video ID 2?version=3&cc_load_policy=1"));
my_loader2.contentLoaderInfo.addEventListener(Even t.INIT, onLoaderInit2);
while (my_player.numChildren > 0)
{
my_player.removeChildAt(0);
my_player.pauseVideo();
}
}
function onLoaderInit2(e:Event):void{
addChild(my_loader2);
my_loader2.x = 170;
my_loader2.y = 50;
my_player2 = my_loader2.content;
my_player2.addEventListener("onReady", onPlayerReady2);
}
function onPlayerReady2(e:Event):void{
my_player2.setSize(550,400);
my_player2.loadVideoById("video ID 2",46);
}
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|