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

Link properties play media actionage!

aijmccrea
Registered: May 19 2008
Posts: 4

Total newbie here looking for a bit of a hand!
I want to create an embedded audio file which I can play and pause and resume with a mouse click using the same link. I have added three actions to the link properties window - play, pause, resume but every 2nd click just plays the audio from the start again. Is there anyway to do this with javascript
Cheers for any help
Aaron

My Product Information:
Acrobat Standard 7.0.9, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
All the actions you add to an event execute one after the other in the order they are placed. So everytime the button is pushed it runs Play, Pause, Resume.

To rotate actions on the same button, a software construction called a state machine is necessary. The statemachine keeps track of what the last action was and controls wich action is next. Here's a simple one in JavaScript that could be placed on a button's Mouse Up action.

if(!this.myState)this.myState = "Start"; switch(this.myState){case "Start":this.myState = "Playing";this.sounds[0].play();break;case "Playing":this.myState = "Paused";this.sounds[0].pause();break;case "Paused":this.myState = "Start";this.sounds[0].pause();break;}

I haven't tested this code, so use it at your own risk. It assumes the audio is in a sound object, not a multimedia object.

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

aijmccrea
Registered: May 19 2008
Posts: 4
Hey there! Many thanks for your response.
I'm trying to play linked/embedded Mp3 files - "play media acrobat 6 compatible"
The custoim javascript starts like this
/* var player = */ app.media.openPlayer({
/* events, settings, etc. */
});
I added you code but no joy. Is there something simple I can change?
Thanks very much
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
The script I presented was just to give you the structure of the state machine you'll need. The Play, Pause, etc. commands are just place holders. I used the functions for the sound annotation. If you added the audio to the PDF with the MultiMedia Annot you'll have to use different functions. Look'em up in the Acrobat JavaScript Reference. You'll find examples in there, and in the Acrobat JavaScript Guide. Very useful documents.

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

aijmccrea
Registered: May 19 2008
Posts: 4
Sorry to be a real pain here but I checked those documents you mentioned and couldn't really find an answer. The best I could come up with was this
if(!this.myState)
this.myState = "Start";

switch(this.myState)
{
case "Start":
this.myState = "Playing";
this.mediaPlayer.play();
break;
case "Playing":
this.myState = "Paused";
this.mediaPlayer.pause();
break;
case "Paused":
this.myState = "Start";
this.mediaPlayer.pause();
break;
}

Any ideas where I'm going wrong?
Thanks again
Aaron
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Ok, you need to do some debug. First, is the media player object valid? If you're having trouble with this part you should figure out what code you'll need in the Console Window. Once you can acquire the player and get it playing, then use that code in this script.

If the player is valid and it's still not working, then put some console.println() statements in the code to display info about what the script is doing.

You can find out about using the Console Window here:
http://www.acrobatusers.com/tech_corners/javascript_corner/tips/2006/javascript_console/

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