These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Need to stop the flash media for app.media.openplayer

mandaracrobat2009
Registered: Mar 16 2009
Posts: 10

Hi, I have created one button to stop the playing flash media. I have written custom javascript like below mentioned but for some reason it's not working. Also I can't use the default stop method provided because I will be using this javascript in other tool. Could you please help me on this?

var annot= this.media.getAnnot({ nPage: 1, cAnnotTitle: "test.swf" });

var rendition = this.media.getRendition("Rendition-Test");

var settings = app.media.getRenditionSettings({ rendition: rendition });
settings.windowType=app.media.windowType.docked;
settings.autoPlay = false;
settings.repeat = 0;

var args = { rendition: rendition, annot: annot, settings: settings};

var player = app.media.openPlayer( args )
player.stop();

thomp
Expert
Registered: Feb 15 2006
Posts: 4411
What version of Acrobat are you using? Was this "swf" file added with the Rich Media(i.e. Flash) tool, or with the older screen annotation? The code you've shown above is for handling the old screen annotation.

Open the properties dialog for the Media, if "Edit Flash" is on the title bar for the window, you have a Rich Media annotation and the code above won't work. If "Multimedia Properties", then you have a screen annotation and the code you have above won't work because it has a bug in it.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

mandaracrobat2009
Registered: Mar 16 2009
Posts: 10
Thanks Thom...

I am using Acrobat 8 and I can see the 'multimedia properties' but not 'edit flash'. If there is bug in it, could you please let me how to proceed to get the javascript to stop the running flash media object (swf file) or what is the alternative to address this issue?

Thanks in advance!!
Mandar
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Since the player is already open an running, there is no need to use the "app.media.openPlayer()" function. Instead, use the "doc.media.getOpenPlayers()" function. If there is only one player open and running, then try running this code from the console window before putting it in button script.
this.media.getOpenPlayers()[0].stop();
Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

mandaracrobat2009
Registered: Mar 16 2009
Posts: 10
Thanks Thom....

I tried with following code but it's not working still. Need your suggestion in the following piece of code.

var oDoc = this;
var players = doc.media.getOpenPlayers(oDoc);
for (var i in players) players[i].stop();

In javascript debugger console, it's showing error as "ReferenceError: doc is not defined
2:Field:Mouse UpException in line 2 of function top_level, script Field:Mouse Up"

I have put this code for button script where I am assigning the whole pdf document in variable 'oDoc' and trying to stop all the playing flash medias in the open pdf document. Is this correct code/method for the desired result?

Thanks for your help!!
Mandar
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Did you look at the examples in the Acrobat JavaScript Reference? This function does not have any arguments. The "doc" in "doc.media" refers to the Document Object.

Try this:

var players = this.media.getOpenPlayers();

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

mandaracrobat2009
Registered: Mar 16 2009
Posts: 10
Thanks Thom....

I tried with below code:

var players = this.media.getOpenPlayers();
players[0].stop();

But still, I am getting below error in console:

TypeError: players[0] has no properties
3:AcroForm:Button1:Annot1:MouseUp:Action1Exception in line 3 of function top_level, script AcroForm:Button1:Annot1:MouseUp:Action1

TypeError: players[0] has no properties
3:AcroForm:Button1:Annot1:MouseUp:Action1

I am not very expert in JS so would be great if you could help me in resolving this issue.

Thanks in advance!!
Mandar
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
If "players[0]" is null, then there are no players open. Is the media playing when you run this code?

Have you tried just using the "PlayMedia" Action. This Action provides several options, "pause", "stop", etc. Please try this first before continuing down the JavaScript Path.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

mandaracrobat2009
Registered: Mar 16 2009
Posts: 10
Yes, I tried with play media action provided by Acrobat. Play and Stop work well there ( Puase doesn't work). But I can't use that action directly because it doesn't generate any javascript which I can use. Actually, I need to generate the pdf output through other application programatically and while generating that pdf, I need to add the particular javascript which will add the play/pause controls for each flash media....So need your help on that...Would be great you could help me with some snippet of working code in your envn (Acrobat 8).

Thanks in advance!!
Mandar
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Well, if you are also doing the play, then that's a different story. The Play code must be returning a Player object, yes? Save the player in a document level variable. Then use it in the other scripts for stop and pause. In the stop script, set this player object variable to null. Then always test for it in the other scripts. That way you always know if the player is on or not.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

mandaracrobat2009
Registered: Mar 16 2009
Posts: 10
Thanks Thom...I tried with all the possibilities but for some reason it's not working. I think, I am doing wrong something in arguments. I have the test.pdf (96kb). Could you please have a look at it and let me know what wrong I am doing there? I want to send that file to you which has javascript code that currently I have wrotten. Could you please let me know if your email id or some other way where I can put that file. My email is mandar [dot] jagtap [at] gmail [dot] com.Thanks in advance!!
Mandar
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
You can post the file at www.Acrobat.com. But I can't promise I'll look at it. You say that you are only having a problem with Pause, both play and stop work? May be that the Flash player doesn't handle the standard Pause. I'm not sure, but if you are able to start the start and stop the player from console window, then you should also be able to test the other operations from there as well.

On another note. Flash media usually provide thier own player controls. Can you place a pause button on the Flash?

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

mandaracrobat2009
Registered: Mar 16 2009
Posts: 10
Hi Thom,

Sorry for the delay!! Actually, No button-script is working. I created play, stop and pause but unfortunately none of them is working. I have uploaded the sample pdf file at acrobat.com. It would be great if you could have a look at it and suggest on it.

https://share.acrobat.com/adc/document.do?docid=83ea8d2f-a860-4584-a117-a1aa930aa452

Thanks in advance!!
Mandar
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Interesting. Apparently this Flash does not recognize options like stop and pause? I was able to start and close the player, but nothing else. The player would not even return a value for the where() function. I think the issue is in the media and not in the Acrobat/Player interface. I've written controlers for flash before and have been able to pause and stop the player. This looks like a Flex application, rather than video, so I suspect that has something to do with it.

There are a couple of issues. First, there is a check box on the Rendition properties dialog for making the rendition visible to JavaScript, it wasn't checked.

Second, unless you need to do something special with the media player, all you really need in the Play button is this:
var annot = <same code >;var rendition = <same code>;app.media.startPlayer({annot:annot, rendition:rendition});

Where is what you already have.And in the Close button, this code works:

this.media.getOpenPlayers()[0].close(3);

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

mandaracrobat2009
Registered: Mar 16 2009
Posts: 10
Thanks a ton Thom...

I tried with your suggestion to use close() function for other different flash media. When I add the flash media object manully in pdf document in acrobat 8.0, it's stopping the player with close() function. I am generating the pdf document through iText from xml to pdf and also adding one button with same javascript code associated with it. iText is adding the flash media in pdf output document with "Rendition is accessible to javascript" ( in "General rendition settings") as *disabled*. And when I add the same media manually in pdf through acrobat, this option is not disabled ( even thogh it's not checked in both cases). Could you please help me to know, what could be the reason for getting "Rendition is accessible to javascript" as disabled when I generate the pdf through iText?

Thanks in advance!!
Mandar
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
When you manually add media to a PDF with the "movie" tool, the media (rendition) data is written into the screen annotation COS object. The movie tool is really a screen annotation tool. If you check the "make accessible to JS" check box, the media is moved into the PDF name tree. This is where the JS looks for renditions in the document. I haven't explored these structures in detail, but I suspect there's more to it. iText is probably writing the media into the name tree, but not putting all the details in place so that when you open the screen annot properties it's confused and just grays out the check box.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script