locked
FACING ISSUE WHILE CHANGING THE POSITION OF MEDIA ELEMENT

    Question

  • In my  windows 8.1 surface  app project Iam working with Media ELement. I have a service that return the source url for the media element and the words in that media element along with their start time and time.
    While playing media element if my media element reaches the time of any word in that service i should highlight the word in my page from that start time to end time. For highlighting the word there is seperate logic.

    What i did was I have added timeline markers for the media element with the start times of all the words. When marker reached event is raised I am highlighting the word whose start time is same as marker time.
    If i dont forward the audio it is playing perfectly with out any glitches.

    If i tap on a word it should take the start time of that word and media element should forward to that position. So what i am doing is when I Tap on it Iam assigning the start of that word to media element position.

    Now the issue is when iam assigning new position word is getting highlighted at correct time. But media element is reading the two words back to the current word.

           For eg: I have a sentence "Windows 8 applications can be developed using XAML."

         For the first time at 1300 miliiseconds it reads "can" .If I explicitly assign the position as 1300 to the media element it reads applications.


       Can anyone help me why there is delay in media element position while forwarding.

    Friday, October 17, 2014 3:57 AM

Answers

  • There are two problems. First, MediaElement can only set the position once the media is loaded, determined by handling the MediaOpened event. Secondly, not all media is seekable. Check by callingCanSeek. Use something like:

    playbackElement1.AutoPlay = true;
    // Will fire after the media has loaded
    playbackElement1.MediaOpened += (source, args) =>
    {
        MediaElement player = (MediaElement) source;
        if (player.CanSeek)
        {
            player.Position = new TimeSpan(0, 0, 0, 0, 5000);   
        }
    }                     
    playbackElement1.SetSource(stream, this.m_recordStorageFile.FileType);

    Once loaded, use the NaturalDuration property to see the length of the media, converting it to a TimeSpan using HasTimeSpan and TimeSpan properties if needed.

    Monday, November 3, 2014 7:15 AM

All replies

  • Can fix this without seeing source code. Please post code to OneDrive and share a link here.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Friday, October 17, 2014 12:55 PM
    Moderator
  • Hi Matt

       Thanks For your reply...

        Please find the below link..

        onedrive.live.com/redir?resid=6D98437759CA625F!106&authkey=!ADqQYkI3sFEo7qs&ithint=file% 2czip

        I had done one sample app to show case my issue.

             The sample in my link contains a media player sample.with three scenarios.

    1.Playing a media file : Plays audio  file normally on clicking select a media file button.

       2.Using markers :

       Plays a media file normally on clicking  select a media file button.

        Added a timeline marker at position 20080 milliseconds. Audio gets paused on reaching the marker. Please observe that audio gets paused  after spelling the word “the”.

    3.Updating the current position of audio element :   

     Plays a media file on clicking select a media file button. On clicking forward button position gets updated to 20080 milliseconds. Please observe that it spells the word “role” .

                          In scenarios 2 and 3 the position is same 20080 milliseconds .But the media element spells different words “the” and “role”. Is there any issue if we update the position with milliseconds. ecause of this lagging Iam facing above mentioned issue in my project.

       It will be very helpful for me if you suggest any solution for this.


         

    Saturday, October 18, 2014 11:27 AM
  • Hi - I don't see any spelling of words in this app. Am I missing something?

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Monday, October 27, 2014 2:34 PM
    Moderator
  • Hi Matt

        With out forwarding audio time if I play the audio normally I can hear one word at some specified milliseconds(In the above scenario it is 20080 milli seconds).

        With out forwarding the audio I can hear word "the" at 20080 milliseconds.

       If I forward my audio by clicking on forward button I can hear word "role" which is two words behind the word "the" .

         To simplify my question Is there any delay of 1s if I update the position of audio element than playing it normally.

    Saturday, November 1, 2014 12:03 PM
  • There are two problems. First, MediaElement can only set the position once the media is loaded, determined by handling the MediaOpened event. Secondly, not all media is seekable. Check by callingCanSeek. Use something like:

    playbackElement1.AutoPlay = true;
    // Will fire after the media has loaded
    playbackElement1.MediaOpened += (source, args) =>
    {
        MediaElement player = (MediaElement) source;
        if (player.CanSeek)
        {
            player.Position = new TimeSpan(0, 0, 0, 0, 5000);   
        }
    }                     
    playbackElement1.SetSource(stream, this.m_recordStorageFile.FileType);

    Once loaded, use the NaturalDuration property to see the length of the media, converting it to a TimeSpan using HasTimeSpan and TimeSpan properties if needed.

    Monday, November 3, 2014 7:15 AM