Play button is not working

4 posts, 0 answers
  1. Nikhil
    Nikhil avatar
    7 posts
    Member since:
    Aug 2012

    Posted 27 Aug 2012 Link to this post

    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
  2. Miro Miroslavov
    Admin
    Miro Miroslavov avatar
    588 posts

    Posted 29 Aug 2012 Link to this post

    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.

  3. DevCraft banner
  4. Nikhil
    Nikhil avatar
    7 posts
    Member since:
    Aug 2012

    Posted 30 Aug 2012 Link to this post

    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
  5. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 03 Sep 2012 Link to this post

    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.

Back to Top