Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Mikael Ekström 14 posts 114 karma points
    Oct 29, 2017 @ 11:32
    Mikael Ekström
    0

    Getting media configured in Media Picker

    I have run into a problem while building a Macro that gets a url for a media file configured in a Media Picker.

    My code:

    @{
    var videoId = Model.MacroParameters["video"];
    var video = Umbraco.Media(videoId.ToString());
        }
        @videoId
        <video width="100%" autoplay>
          <source src="@video.Url" type="video/mp4">
        Your browser does not support the video tag.
        </video>
    

    I get the videoId that looks like this:

    umb://media/139b85f3b3d5459cab79a5a36c2b1006

    When i then try to get the media using Umbraco.Media(videoId) i get nothing back, what am I doing wrong?

  • Alex Skrypnyk 6182 posts 24284 karma points MVP 8x admin c-trib
    Oct 29, 2017 @ 13:38
    Alex Skrypnyk
    0

    Try this one :

    @{
    Udi ;
    if(Udi.TryParse(videoId.ToString(), out udi))
    {
    var video = Umbraco.TypedMedia(udi);
    
        <video width="100%" autoplay>
          <source src="@video.Url" type="video/mp4">
        Your browser does not support the video tag.
        </video>
    }
    
        }
    
  • Mikael Ekström 14 posts 114 karma points
    Oct 30, 2017 @ 08:37
    Mikael Ekström
    0

    Updated code:

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    @{
        var videoId = Model.MacroParameters["video"];
        if (Udi.TryParse(videoId.ToString(), out Udi udi))
        {
            var video = Umbraco.TypedMedia(udi);
        }
    }
    @video
    <video width="100%" autoplay>
      <source src="@video.Url" type="video/mp4">
    Your browser does not support the video tag.
    </video>
    

    Gives an error:

    System.Web.HttpCompileException (0x80004005): h:\root\home\navigatum-001\www\klimatvision\Views\MacroPartials\Video player.cshtml(4): error CS1026: ) expected
    

    Cant really figure out why its missing a ")"?

  • Alex Skrypnyk 6182 posts 24284 karma points MVP 8x admin c-trib
    Oct 30, 2017 @ 08:43
    Alex Skrypnyk
    0

    Hi Mikael

    try this code, it's working for me:

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    @{
        var videoId = Model.MacroParameters["video"];
        IPublishedContent video = null;
        Udi udi;
        if (Udi.TryParse(videoId.ToString(), out udi))
        {
            video = Umbraco.TypedMedia(udi);
        }
    }
    
    @video
    @if (video != null)
    {
        <video width="100%" autoplay>
            <source src="@video.Url" type="video/mp4">
            Your browser does not support the video tag.
        </video>
    }
    

    Thanks,

    Alex

  • Alex Skrypnyk 6182 posts 24284 karma points MVP 8x admin c-trib
    Nov 01, 2017 @ 13:01
    Alex Skrypnyk
    1

    Hi Mikael

    Did you solve the issue? Share with our community, please )

    Thanks,

    Alex

  • Mikael Ekström 14 posts 114 karma points
    Nov 01, 2017 @ 13:30
    Mikael Ekström
    100

    Here is the code of the macro that is now running and working on my site:

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    @{
            var videoId = Model.MacroParameters["video"];
            var video = Umbraco.Media(videoId);
       }
    
    <video width="100%" controls loop muted playsinline autoplay>
    <source src="@video.Url" type="video/mp4">
    Your browser does not support the video tag.
    </video>
    

    Tested to also work with iphone and to scale properly.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies