Play video stored in database

9 posts, 0 answers
  1. RAVINDRA
    RAVINDRA avatar
    47 posts
    Member since:
    Dec 2010

    Posted 16 Jun 2011 Link to this post

    Hi

    I am storing the video in database as byte[]. Please let me know how do I use the byte[] to play the video??

    Thanks
    Ravindra

  2. Tina Stancheva
    Admin
    Tina Stancheva avatar
    2812 posts
    Member since:
    Apr 2014

    Posted 16 Jun 2011 Link to this post

    Hi RAVINDRA,

    The RadMediaPlayer is basically a wrapper around the Silverlight's MediaElement control. Therefore RadMediaPlayer supports the same media formats as SIlverlight's MediaElement does. You can find a full list of the supported media formats here.

    In cases when you want to use a byte stream to set the RadMediaPlayer items, you can set the RadMediaPlayer.MediaElement source:

    //buffer is the byte array
    Stream stream = new MemoryStream(buffer);
      
    mediaPlayer.MediaElement.SetSource(stream);
    Unfortunately there is a known issue when setting the RadMediaPlayer source like this - a null reference exception is thrown. The item is logged in our PITS, where you can track its progress.

    This is why it might be better to keep your videos on the server and keep in the database only the addresses/information of the files. Then you will be able to define the RadMediaPalyer playlist using the address of each video file.



    Best wishes,
    Tina Stancheva
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

  3. Nina
    Nina avatar
    5 posts
    Member since:
    Jun 2010

    Posted 08 Mar 2012 Link to this post

    Dear Tina,
    I am sorry.
    Is it true? Telerik MEdia Player CANNOT play stream.
    I am using Silverlight MediaPlayer from Windows.Controls to play Back stream from "TExt to Speech".
    And Now try to use Silverilght Telerik MEdiaPLayer.  And I got MediaElement equals NULL.
    Tell me, please ,  Is it no chance to use Telerik for stream not for file?
    THank you advanced.
    Nina

  4. Tina Stancheva
    Admin
    Tina Stancheva avatar
    2812 posts
    Member since:
    Apr 2014

    Posted 13 Mar 2012 Link to this post

    Hi Nina,

    The RadMediaPlayer.MediaElement property is of type MediaElement and you should be able to use it as the MS MediaElement, which you've previously used. But in order to access the MediaElement you'll need to make sure that the RadMediaPlayer is fully initialized. For that purpose you can handle the MediaPlayer.Loaded event and get the MeidaElement in a Dispatcher like this:

    private void myMediaPlayer_Loaded(object sender, RoutedEventArgs e)
    {
        Dispatcher.BeginInvoke(() =>
        {
            var mediaElement = (sender as RadMediaPlayer).MediaElement;
            if (mediaElement != null)
            {
            }
        });
    }

    Unfortunately the RadMediaPlayer issue with opening files from the client machine is still not fixed and this may cause issues while implementing your scenario.

    All the best,
    Tina Stancheva
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>

  5. Nina
    Nina avatar
    5 posts
    Member since:
    Jun 2010

    Posted 13 Mar 2012 Link to this post

    THanks Tina it works.
    NIna

  6. Barry
    Barry avatar
    11 posts
    Member since:
    Dec 2008

    Posted 18 Mar 2012 Link to this post

    Hi Tina,

    I am also trying to play a media item from a byte[] stored in a database. I see that there is a known bug for some time around the mediaitem being null. I have tried to use your suggested work around but I find even on the loaded event for the radmediaplayer the mediaitem is still null.

    My xaml declaration is:

            <telerik1:RadMediaPlayer Canvas.Left="38" Canvas.Top="37" Height="79" Name="radMediaPlayer1" Width="287"
                                     IsPlaylistVisible="False" FullScreenChanged="mediaPlayer_FullScreenChanged"
                                     AutoPlay="False" CurrentStateChanged="radMediaPlayer1_CurrentStateChanged"
                                     SelectedIndex="0" IsFullScreen="False" Background="Black" Loaded="radMediaPlayer1_Loaded">

    My code behind is:

      private void radMediaPlayer1_Loaded(object sender, RoutedEventArgs e)
            {
                Dispatcher.BeginInvoke(() =>
                {
                    var mediaElement = (sender as RadMediaPlayer).MediaElement;
                    if (mediaElement != null)
                    {
                    }
                });
            }
    I have set break points on this method and can see that the mediaitem for the player is still null even though the Loaded event has fired.

    Are there any other work arounds that I can try.

    regards
    Barry

  7. Tina Stancheva
    Admin
    Tina Stancheva avatar
    2812 posts
    Member since:
    Apr 2014

    Posted 21 Mar 2012 Link to this post

    Hello Barry,

    We aren't aware of any workarounds. However as I am not sure how you implement your scenario, it might be better to send us a sample project demonstrating your approach. This way we'll be able to look for workarounds in your particular case.

    Regards,
    Tina Stancheva
    the Telerik team

    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>

  8. Naga Sridhar madiraju
    Naga Sridhar madiraju avatar
    10 posts
    Member since:
    Mar 2010

    Posted 16 May 2013 Link to this post

    Hi Tina,

    Can we assign multiple byte[] or Streams 


     

    byte[] outputBytes = new byte[arrayA.Length + arrayB.Length];
    Buffer.BlockCopy(arrayA, 0, outputBytes, 0, arrayA.Length);
    Buffer.BlockCopy(arrayB, 0, outputBytes, arrayA.Length, arrayB.Length);
     
    Stream msOut = new MemoryStream(outputBytes);
    Player.MediaElement.SetSource(msOut);

    I'll be reading multiple byte[], and concatenate those to player source,
    the problem now is, it's just playing the first stream.


    Help appreciated

    Thanks,
    Sridhar

  9. Tina Stancheva
    Admin
    Tina Stancheva avatar
    2812 posts
    Member since:
    Apr 2014

    Posted 20 May 2013 Link to this post

    Hello Sridhar,

    RadMediaPlayer is simply a wrapper around the MediaElement control and both controls can't handle this scenario. It might be better to implement the approach we suggested in your other thread or look for a tool that allows you to merge media files. If you use a tool that merges two video files together and you give the MediaElement a proper stream of a proper media file, only then it can play and read the extended length of the movie.

    Otherwise eve though you provide an extended stream, its media-related data isn't changed. The stream doesn't really represent a new (proper and longer) media file and it cannot be displayed as such by MediaElement or RadMediPlayer.

    Kind regards,
    Tina Stancheva
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top