none
Starting audio/video within a timeline?

    Question

  • Currently using Blend 2 September Preview and Orcas 2008 Beta 2.

    My timeline starts on page load and I want to have an audio file begin at 3 seconds within my timeline. I've tried a few different ways of doing this but cannot. I could easily create an event for this but how can I have the event begin at 3 seconds in my timeline.

    Thanks,

    Nick

    Thursday, September 20, 2007 9:40 AM

Answers

  • Can you provide an example of this? I cannot find information pertaining to this issue.

    <Storyboard x:Name="Timeline2" Completed="timeline2completed">

    But how to reference this in the java script to have the media start when this time line is completed? Right now, the audio plays on canvas loaded.

    Do I need to move my:

    <MediaElement x:Name="explosion_mp3" Width="0" Height="0" Canvas.Left="522.228" Canvas.Top="624.508" Source="explosion.mp3" Stretch="Fill"/>

    to another location in the xaml?

    Thursday, September 20, 2007 12:32 PM
  • The 2nd timeline is running onload. Which is fine. I have set the timeline to last 2.2 seconds.

    I am trying to call the audio to play on timeline2 completed, so that the audio begins at 2.2 seconds to match with an animation that is happening in timeline1. (falling object hits at 2.2 seconds and thus needs to make a sound on striking the object)

    This is where I am getting confused. How to set up my xaml/js to only fire the mediaelement on timeline2 completed. As of now, it is firing on canvas load. If there is another way of getting the audio to start at a certain point of a timeline let me know. But this appears to be the only way and I don't seem to be able to use the correct functionality.

    Thursday, September 20, 2007 12:53 PM
  • Set the AutoPlay property to false (the default is true, which is why the sound is starting on load). in the complete event handler of the storyboard write the following code:

    timeline2completed = function(sender) {
        sender.getHost().content.findName("explosion_mp3").play();
    }
     

    Thursday, September 20, 2007 1:05 PM
  • Yes. I just found the Autoplay=false function just before reading your post I got it to work. Here is how I did it for anyone in the future.

    Made my reference in the timeline2 completed="begin" in my xaml.

    And my JS looks like this:

    {

    handleLoad:
    function begin(sender, args)

    {

    sender.findName(
    "explosion_mp3").Play();

    }

    Thanks for your help.. just needed to look harder.

    Thursday, September 20, 2007 1:12 PM

All replies

  • The only event you can set is on the StoryBoard object (Completed event), you can not set the even on a keyframe. So as a work around you need to create another storyboard with 3 seconds time, start the two storyboards at the same time and on the completed event of the second storyboard you can start the video.
    Thursday, September 20, 2007 9:57 AM
  • Can you provide an example of this? I cannot find information pertaining to this issue.

    <Storyboard x:Name="Timeline2" Completed="timeline2completed">

    But how to reference this in the java script to have the media start when this time line is completed? Right now, the audio plays on canvas loaded.

    Do I need to move my:

    <MediaElement x:Name="explosion_mp3" Width="0" Height="0" Canvas.Left="522.228" Canvas.Top="624.508" Source="explosion.mp3" Stretch="Fill"/>

    to another location in the xaml?

    Thursday, September 20, 2007 12:32 PM
  • You can use findName method to retrieve a reference to the Storyboard and start it, if you are starting the storyboard from an event handler, you can do it like this:

    myEventHandler = function(sender) {
        timeline = sender.getHost().cintent.findName("Timeline2");
        timeline.stop();
        timeline.befin();
    }
     

    The call to the stop method is necessary if you are calling the timeline more than once. 

    Thursday, September 20, 2007 12:42 PM
  • The 2nd timeline is running onload. Which is fine. I have set the timeline to last 2.2 seconds.

    I am trying to call the audio to play on timeline2 completed, so that the audio begins at 2.2 seconds to match with an animation that is happening in timeline1. (falling object hits at 2.2 seconds and thus needs to make a sound on striking the object)

    This is where I am getting confused. How to set up my xaml/js to only fire the mediaelement on timeline2 completed. As of now, it is firing on canvas load. If there is another way of getting the audio to start at a certain point of a timeline let me know. But this appears to be the only way and I don't seem to be able to use the correct functionality.

    Thursday, September 20, 2007 12:53 PM
  • Set the AutoPlay property to false (the default is true, which is why the sound is starting on load). in the complete event handler of the storyboard write the following code:

    timeline2completed = function(sender) {
        sender.getHost().content.findName("explosion_mp3").play();
    }
     

    Thursday, September 20, 2007 1:05 PM
  • Yes. I just found the Autoplay=false function just before reading your post I got it to work. Here is how I did it for anyone in the future.

    Made my reference in the timeline2 completed="begin" in my xaml.

    And my JS looks like this:

    {

    handleLoad:
    function begin(sender, args)

    {

    sender.findName(
    "explosion_mp3").Play();

    }

    Thanks for your help.. just needed to look harder.

    Thursday, September 20, 2007 1:12 PM
  • Glad that the problem has been solved, can you please mark the post that helped you as the answer?
    Thursday, September 20, 2007 1:15 PM