Create RadMediaItem from file

22 posts, 0 answers
  1. Helen
    Helen avatar
    101 posts
    Member since:
    Nov 2008

    Posted 27 Apr 2009 Link to this post

    Is there any way to create a RadMediaItem to play by choosing a file from the local file system?

    thx

    Helen
  2. Helen
    Helen avatar
    101 posts
    Member since:
    Nov 2008

    Posted 27 Apr 2009 Link to this post

    Never mind, I found a work-around by setting the Player's MediaElement's source to a file stream, and then playing it.
  3. DevCraft banner
  4. Dan M
    Dan M avatar
    4 posts
    Member since:
    Sep 2009

    Posted 03 Nov 2009 Link to this post

    Has anyone found a solution for the initial question?
  5. Kiril Stanoev
    Admin
    Kiril Stanoev avatar
    1511 posts

    Posted 04 Nov 2009 Link to this post

    Hello Dan,

    Currently this scenario is not supported by RadMediaPlayer. Future versions of RadMediaPlayer will definitely support this functionality, but for the moment, the only way to play a local file is to pass its stream to RadMediaPlayer's MediaElement.

    private void BrowseButton_Click(object sender, RoutedEventArgs e)
    {
        OpenFileDialog openFileDialog1 = new OpenFileDialog();
     
        if (openFileDialog1.ShowDialog() == true)
        {
            Stream fileStream = openFileDialog1.File.OpenRead();
            mediaPlayer.MediaElement.SetSource(fileStream);
        }
    }

    I am attaching my sample project for further reference.

    Kind regards,
    Kiril Stanoev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  6. savitha d
    savitha d avatar
    1 posts
    Member since:
    Nov 2009

    Posted 01 Dec 2009 Link to this post

    Can i take the Souce from direct  local path i dont need openfiledialog is it possible?
  7. Kiril Stanoev
    Admin
    Kiril Stanoev avatar
    1511 posts

    Posted 02 Dec 2009 Link to this post

    Hi Savitha,

    In Silverlight, the only way to gain access to the local file system is through the OpenFileDialog / SaveFileDialog classes.

    Regards,
    Kiril Stanoev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  8. Helen
    Helen avatar
    101 posts
    Member since:
    Nov 2008

    Posted 14 Apr 2010 Link to this post

    When I run the code using the latest version and I use the "Browse" button to set the MediaElement, it throws the following exception:

     

    {System.Windows.ApplicationUnhandledExceptionEventArgs}
        base {System.EventArgs}: {System.Windows.ApplicationUnhandledExceptionEventArgs}
        ExceptionObject: {System.NullReferenceException: Object reference not set to an instance of an object.
       at Telerik.Windows.Controls.ItemsControlExtensions.<GetContainers>d__0`1.MoveNext()
       at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
       at System.Linq.OrderedEnumerable`1.<GetEnumerator>d__0.MoveNext()
       at Telerik.Windows.Controls.RadMediaPlayer.SetTickMarksOnTimeSlider()
       at Telerik.Windows.Controls.RadMediaPlayer.MediaElement_MediaOpened(Object sender, RoutedEventArgs e)
       at MS.Internal.CoreInvokeHandler.InvokeEventHandler(Int32 typeIndex, Delegate handlerDelegate, Object sender, Object args)
       at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, String eventName)}
        Handled: false

  9. Miro Miroslavov
    Admin
    Miro Miroslavov avatar
    588 posts

    Posted 16 Apr 2010 Link to this post

    Hello Helen,

    Thank you for reporting this issue. We'll fix it as soon as possible.
    Till then you can workaround it with setting the mediaPlayer.SelectedIndex = 0.
    <telerikMediaPlayer:RadMediaPlayer x:Name="mediaPlayer" Width="800" Height="600"
                        SelectedIndex="0">

    Hope this works for you.

    Sincerely yours,
    Miro Miroslavov
    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.
  10. Helen
    Helen avatar
    101 posts
    Member since:
    Nov 2008

    Posted 16 Apr 2010 Link to this post

    Hi guys,

    Your fix works in a simple project, but when I try to use the RadMediaPlayer in a bigger project, I get the same error, even when I add the SelectedIndex="0" to the Xaml for the RadMediaPlayer.

    So please let me know when you have a fix.

    Best

    Helen
  11. Miro Miroslavov
    Admin
    Miro Miroslavov avatar
    588 posts

    Posted 21 Apr 2010 Link to this post

    Hello Helen,

    It's logged and should be fixed. Till then, we can provide you help support if needed. You can send us example project where you get error, so we can think of workaround.

    All the best,
    Miro Miroslavov
    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.
  12. Helen
    Helen avatar
    101 posts
    Member since:
    Nov 2008

    Posted 20 May 2010 Link to this post

    So -- any idea when the fix will be in? I'm anxious to convert to your media player from the one I am currently using.

    Thx

    Helen
  13. Miro Miroslavov
    Admin
    Miro Miroslavov avatar
    588 posts

    Posted 27 May 2010 Link to this post

    Hi Helen,

    At the moment we can't promise you exact date.
    Sorry for the inconvenience.

    Greetings,
    Miro Miroslavov
    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.
  14. Manuel Felício
    Manuel Felício avatar
    64 posts
    Member since:
    Oct 2009

    Posted 28 Jun 2010 Link to this post

    We are trying to use RadMediaPlayer and we're getting the same issue. It seems at the moment RadMediaPlayer is pretty useless unless you can fix the ALWAYS throwing NullReferenceException when we set an the MediaElement source.

    Another strange thing is that the MediaElement property is null after the RadMediaPlayer loaded event is fired, but if I have a button somewhere and click it then the MediaElement property has a value, so there must be some backround running task that must complete before the MediaElement gets set, but I don't know when it completes..

    In my case I have an in-memory byte[] stream that I want to play. I open a RadWindow, find a view that can play a specified type of file, in this case it would be the RadMediaPlayer, put it in the Window and set the MediaElements' Source to my stream..fails (NullReferenceException).

    Any clues?

    Edit: don't get me wrong.. I might have sounded a little bit rude here but the fact is that RadMediaPlayer does a lot of complex stuff in a wonderful way but it fails to do the basic stuff, which is very frustrating..
  15. Manuel Felício
    Manuel Felício avatar
    64 posts
    Member since:
    Oct 2009

    Posted 29 Jun 2010 Link to this post

    Well, here goes my current work-around:

    void MainPage_Loaded(object sender, RoutedEventArgs e)  
            {  
                Dispatcher.BeginInvoke(() => 
                {  

                       player.Items.Clear();

                    var stream = typeof(MainPage).Assembly.GetManifestResourceStream("SilverlightApplication1.Assets.Wildlife.wmv");  
                    player.MediaElement.SetSource(stream);  
                });  
            } 

    Notice that in the loaded event the MediaElement is null, but when the delegate I pass to the BeginInvoke method gets called the MediaElement is not null anymore.. I'm not sure if this happens all the time, but for now it works.

    In the Xaml I have the media player with a sample video and SelectedIndex=0.

    Best regards,

    Manuel Felício.
  16. Manuel Felício
    Manuel Felício avatar
    64 posts
    Member since:
    Oct 2009

    Posted 29 Jun 2010 Link to this post

    Digging deeper, I've created an HttpHandler and I'm streaming the binary file to the HttpResponse OutputStream. This way allows me to use RadMediaItem's with Uri sources.

    Everything is working great, I'm surprised it works for different types of files without me having to specify the content-type of the HttpResponse.

    The only problem is that since this isn't a real streaming service I don't support seeking, but I haven't found a way in RadMediaPlayer to disable seeking to a position that hasn't been downloaded yet. For example, I should be able to seek to a position that I've already downloaded but not to a position that hasn't been downloaded yet. Does this make sense?

    Best regards,

    Manuel Felício.
  17. Miro Miroslavov
    Admin
    Miro Miroslavov avatar
    588 posts

    Posted 30 Jun 2010 Link to this post

    Hello Manuel Felício,

    I get your idea, but RadMediaPlayer doesn't support this scenario. I think that for best user experience, you should use the regular streaming services provided by IIS or some other streaming services.
    If we can be of further help please ask us.

    Greetings,
    Miro Miroslavov
    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
  18. Manuel Felício
    Manuel Felício avatar
    64 posts
    Member since:
    Oct 2009

    Posted 30 Jun 2010 Link to this post

    Thanks for your response.

    Yes you can! :)

    When RadMediaPlayer tries to seek to a position how does that position gets passed in the http request? Is there a way for me to access the seek position in my HttpHandler?

    Best regards,

    MF.
  19. Miro Miroslavov
    Admin
    Miro Miroslavov avatar
    588 posts

    Posted 02 Jul 2010 Link to this post

    Hello Manuel Felício,

    RadMediaPlayer is just a wrapper around the Silverlight build in MediaElement. Which handles internally about everything related to reading the streams, seeking, playing, pausing and etc. And the worst thing is that most of the logic is in native methods.
    This is why we don't have the control over the seeking and i don't think you have a way to access and modify the seek position http requests.

    Regards,
    Miro Miroslavov
    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
  20. Malcolm
    Malcolm avatar
    1 posts
    Member since:
    Jul 2010

    Posted 06 Jan 2011 Link to this post

    Hi Miro Miroslavov,the Telerik team 

    Is there away in which we could pick MediaItems for the RadMediaPlayer directly from the local hard disk? am doing a Touchscreen & idont think it will be agood idea to ask users to pick .WMV files by use of OpenDialog. It will simply bit the logic. or is there a simpler workaround for the same?

    George Moyi
    developer
  21. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 11 Jan 2011 Link to this post

    Hi Helen,

    The RadMediItem in its core is a wrapper around the MediaElement control and as such has no access to the local file system.

    So in order to be able to play video files with Silverlight, you'll need to make them visible to the world (thought http or Media Services...) and after that play them in the RadMediaPlayer as RadMediaItems with source like "http://mydomain.com/Videos/sample.wmv". Or you will have to place them in the folder containing your .xap, so that they can be requested under the same path.

    All the best,
    Tina Stancheva
    the Telerik team
    Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
  22. Greg Sipes
    Greg Sipes avatar
    24 posts
    Member since:
    Apr 2010

    Posted 14 Mar 2011 Link to this post

    Miro,
        Has Helen's issue been fixed yet? I am having the same problem. I also attempted to add the SelectedIndex = 0, but no luck. I saw in another forum, that I should check the mediaFailed event of the mediaElement, but that doesn't get hit before the debugging error is thrown.Any ideas?

    I see Tina's most recent post, but if thats the case, the documenation should not say that it can render a stream, when in fact it needs a file path.

    Thanks in advance,
    Greg
  23. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 17 Mar 2011 Link to this post

    Hi Greg Sipes,

    Unfortunately the issue is still not fixed due to the many pressing tasks in our to-do list. Therefore at the moment you can only play public streams/videos (thought http or Media Services...)

    However, we will do our best to fix this issue as soon as possible. You can track its progress here.

    Please accept our apology for the caused inconvenience.

    Regards,
    Tina Stancheva
    the Telerik team
Back to Top
DevCraft banner