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

Play button is not working

3 Answers 110 Views
MediaPlayer
This is a migrated thread and some comments may be shown as answers.
Nikhil
Top achievements
Rank 1
Nikhil asked on 27 Aug 2012, 03:07 PM
Hi,

i am trying to play a .wav audio file which is stored in database,
but my problem is play button is not working...
please find the below sample code:
i have created one control (hfRadMediaPlayer) which is inherited from RadMediaPlayer :
<local:hfRadMediaPlayer x:Name="hfMediaPlayer" AutoPlay="False"
                                        IsChaptersPanelHidden="True"
                                               Header="{Binding RelativeSource={RelativeSource Self}, Path=MediaElement}"
                                             VerticalContentAlignment="Top" HorizontalContentAlignment="Center"
                                     SelectedIndex="0" IsChaptersPanelPinned="True">
                                    <telerik:RadMediaItem x:Name="RadMediaItemAudio" IsStreamingSource="True" Header="Infinity Media Player" Height="150" Width="300">
                                        <telerik:RadMediaChapter Content="Chapter 1" Position="00:00:50" Height="50" Width="100"/>
                                        <telerik:RadMediaChapter Content="Chapter 2" Position="00:03:00" Height="50" Width="100"/>
                                    </telerik:RadMediaItem>
                                </local:hfRadMediaPlayer>

exposed one Dependency Property to set source to SetSourcemethod:

public static readonly DependencyProperty SetSourceProperty = DependencyProperty.Register("SetSource",
            typeof(MediaStreamSource), typeof(hfRadMediaPlayer), new PropertyMetadata(new PropertyChangedCallback(OnPropertyChanged)));

 public MediaStreamSource SetSource
        {
            get
            {
                return (MediaStreamSource)this.GetValue(SetSourceProperty);
            }

            set
            {
                base.SetValue(SetSourceProperty, value);
                this.MediaElement.SetSource(value);
            }
        }


setting the source like this:private void SetSourceContent(MediaStreamSource radDocument)
        {
            //if (radDocument == null)
            //{
            //    this.Document = new RadMediaPlayer();
            //}
            //else
            //{
            if (this.MediaElement == null)
                this.MediaElement = new MediaElement();

            this.MediaElement.SetSource(radDocument);
            //}
        }
Thanks in advance

3 Answers, 1 is accepted

Sort by
0
Miro Miroslavov
Telerik team
answered on 29 Aug 2012, 08:10 AM
Hi Nikhil,

 I'm not sure why do you need to inherit from the RadMediaPlayer? The player has items and these items have Source property which you should use, instead of your custom SetSource. 
On a side note, you're also not supposed to set the MediaElement property - it is the element part of the Control Template of the control and is populated by the Player itself. Also this is the reason why the Play button doesn't work. 
If you want to use the MediaElement property - you'll have to wait first for the Template to be applied - after the OnApplyTempalte method has been called.
Let us know if you have further questions. 

All the best,
Miro Miroslavov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Nikhil
Top achievements
Rank 1
answered on 30 Aug 2012, 07:12 AM
Hi,

Can you please provide me some sample code , my media file is stored in DB so i am getting byte array, so how to do in this scenario.

Thanks
0
Tina Stancheva
Telerik team
answered on 03 Sep 2012, 04:00 PM
Hi Nikhil,

In order to play a stream in the RadMediaPlayer, you can use the RadMediaPlayer.MediaElement.SetSource(byteArray) method. However, please keep in mind that in order to set the MediaElement source, it has to be defined and it's best to handle the RadMediaPlayer.SizeChanged event to be absolutely sure that the player has fully loaded and its MediaElement is initializaed. You can have a look at this forum post and my last reply as it contains more information, code snippets and a sample solution demonstrating this approach.

Regards,
Tina Stancheva
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
MediaPlayer
Asked by
Nikhil
Top achievements
Rank 1
Answers by
Miro Miroslavov
Telerik team
Nikhil
Top achievements
Rank 1
Tina Stancheva
Telerik team
Share this question
or