This is a migrated thread and some comments may be shown as answers.

Not able to play audio file in repeated order

6 Answers 62 Views
MediaPlayer
This is a migrated thread and some comments may be shown as answers.
Rahul
Top achievements
Rank 1
Rahul asked on 30 May 2013, 01:31 PM
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

6 Answers, 1 is accepted

Sort by
0
Tina Stancheva
Telerik team
answered on 31 May 2013, 07:43 AM
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.

0
Rahul
Top achievements
Rank 1
answered on 12 Jun 2013, 06:44 AM
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);

 

0
Tina Stancheva
Telerik team
answered on 17 Jun 2013, 10:46 AM
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.

0
Paolo
Top achievements
Rank 1
answered on 15 Oct 2013, 12:45 PM
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
0
Hristo
Telerik team
answered on 18 Oct 2013, 02:44 PM
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 >>
0
Paolo
Top achievements
Rank 1
answered on 18 Oct 2013, 04:06 PM
Thanks Hristo, it works!
Tags
MediaPlayer
Asked by
Rahul
Top achievements
Rank 1
Answers by
Tina Stancheva
Telerik team
Rahul
Top achievements
Rank 1
Paolo
Top achievements
Rank 1
Hristo
Telerik team
Share this question
or