Skip to main content
Participant
March 30, 2016
Question

how do I tell embedded sound to stop playing on certain page of pdf?

  • March 30, 2016
  • 1 reply
  • 2274 views

I am making an e-book and want to have songs play to accompany certain pages of the book.

The problem is that if the song doesn't finish playing it continues onto the next page where a new song is supposed to start - so they play over each other.

Is there a way to fix this?

This topic has been closed for replies.

1 reply

JoelGeraci_Datalogics
Participating Frequently
March 31, 2016

Just set the sound object to "Disable When: The page containing the content is closed." in the properties panel.

Participant
March 31, 2016

the only problem is some sounds are meant to continue over multiple pages

JoelGeraci_Datalogics
Participating Frequently
April 1, 2016

Yes, exactly.

The sounds start playing when the user opens to the page with the sound media player on it .

In adobe acrobat I went to tools - content - multimedia - sound - then drew a box and chose the mp3 I wanted to upload.


Ok - I haven't actually tested this code but I think I got it right. If you can send me the file in question, I can check it.

Anyway. Since  the user can activate a rich media annotation in a variety of ways and you can't reliably get a handle to which ones one active, you need to turn every one of them in the document off before starting the one on the page you want.

Add this code to the "Page Open" script for each page with a sound. The code will go through the document page by page looking for sound annotations and turning them off when not on the active page. Then it will turn on the sound on the current page.

// iterate through all the pages in the document and deactivate any playing sound files

for (var i=0;i < this.numPages;i++) {

  // chech that we're not on the current page

  if (i != this.pageNum) {

  // check if the page has a richMediaAnnotation

  if (typeof this.getAnnotsRichMedia(i) !== "undefined") {

  // assuming there is only one sound file

  if (this.getAnnotsRichMedia(i)[0].activated == true) {

  this.getAnnotsRichMedia(i)[0].activated = false;

  }

  }

  }

}

// Activate the sound on the page the user is on.

this.getAnnotsRichMedia(this.pageNum)[0].activated == true;