Not able to play audio file in repeated order

7 posts, 0 answers
  1. Rahul
    Rahul avatar
    3 posts
    Member since:
    May 2013

    Posted 30 May 2013 Link to this post

    Hi,

    My audio file is stored in database in image format, i can able to play the file in first time, but after file played completely if i click on play button again control is not able to play it and not showing any error also.

    Thanks
    Rahul
  2. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 31 May 2013 Link to this post

    Hello Rahul,

    Unfortunately I'm not sure how to go about reproducing this issue. In our demos if you watch a movie and then hit Play again, the movie will be played once more and there are no issues. The control should behave the same way when playing an audio file. This is why I was wondering if you can send over a sample solution we can take a look at. That will help us better understand your implementation and look for a solution.

    Regards,
    Tina Stancheva
    Telerik

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. DevCraft banner
  4. Rahul
    Rahul avatar
    3 posts
    Member since:
    May 2013

    Posted 12 Jun 2013 Link to this post

    Hi Tina,

    Can you please provide any sample in which you are playing media file stored in database ?
    My Implementation are below:

    // DocumentSource is byte array

     

    MemoryStream

     

     

    stream = new MemoryStream(DocumentSource);

     

    if

     

     

    (this.MediaElement == null)

     

     

     

    this.MediaElement = new MediaElement();

     

     

     

    this.MediaElement.SetSource(stream);

     

  5. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 17 Jun 2013 Link to this post

    Hi Rahul,

    If you're using the RadMediaPlayer, then you need to access its MediaElement property. And in order to make sure this property is not null, you can handle the SizeChanged event of the control and set the MediaElement source in it.


    I attached a sample solution where the stream of a file is taken from an OpenFileDialog() rather than a database, but the approach is the same. Basically the OpenFileDialog() allows the user to browse for a video file and then takes the stream of the chosen file. Then if the RadMediaPlayer.MediaElement property is initialized (not null), its source is set. Otherwise, the SizeChanged event of the MediaPlayer is handled to apply a source on the MediaElement.

    I hope this solution can get you started.

    Regards,
    Tina Stancheva
    Telerik

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  6. Paolo
    Paolo avatar
    13 posts
    Member since:
    Mar 2012

    Posted 15 Oct 2013 Link to this post

    Hi Tina,
    I'm having the same problem with RadMediaPlayer: if I choose a file from OpenFileDialog and set it as the MediaElement's source, after file played completely if i click on play button again control is not able to play.
    The sample you attached suffers of hte same problem.

    I also tried to handle the MediaEnded event and reset the position, but nothing happens.

    Any hint to solve this?

    Thanks in advance

    Paolo
  7. Hristo
    Admin
    Hristo avatar
    352 posts

    Posted 18 Oct 2013 Link to this post

    Hello Rahul,

    I have modified Tina's project and managed to solve the issue.

    public MainPage()
    {
        InitializeComponent();
    }
     
    private void xMediaPlayer_SizeChanged(object sender, SizeChangedEventArgs e)
    {
        if (fileStream != null)
        {
            this.xMediaPlayer.MediaElement.Stop();
            this.xMediaPlayer.MediaElement.AutoPlay = false;
            this.xMediaPlayer.MediaElement.SetSource(fileStream);
            this.xMediaPlayer.SizeChanged -= xMediaPlayer_SizeChanged;
            this.xMediaPlayer.MediaElement.CurrentStateChanged += MediaElement_CurrentStateChanged;
        }
    }
     
    Stream fileStream;
    private void OpenFile(object sender, RoutedEventArgs e)
    {
        OpenFileDialog openFileDialog1 = new OpenFileDialog();
        if (openFileDialog1.ShowDialog() == true)
        {
            this.fileStream = openFileDialog1.File.OpenRead();
        }
     
        this.xMediaPlayer.Visibility = Visibility.Visible;
        if (this.xMediaPlayer.MediaElement != null)
        {
            this.xMediaPlayer.MediaElement.Stop();
            this.xMediaPlayer.MediaElement.AutoPlay = false;
            this.xMediaPlayer.MediaElement.SetSource(fileStream);
            this.xMediaPlayer.MediaElement.CurrentStateChanged += MediaElement_CurrentStateChanged;
     
        }
    }
     
    private void MediaElement_CurrentStateChanged(object sender, RoutedEventArgs e)
    {
        if (this.xMediaPlayer.MediaElement.CurrentState == MediaElementState.Closed)
        {
            this.xMediaPlayer.MediaElement.SetSource(fileStream);
        }
    }

    Could give it a try and check whether it works in your case?

    Regards,
    Hristo
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  8. Paolo
    Paolo avatar
    13 posts
    Member since:
    Mar 2012

    Posted 18 Oct 2013 Link to this post

    Thanks Hristo, it works!
Back to Top
DevCraft banner