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?
@{
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>
}
}
@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>
@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>
}
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.
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:
I get the videoId that looks like this:
When i then try to get the media using Umbraco.Media(videoId) i get nothing back, what am I doing wrong?
Try this one :
Updated code:
Gives an error:
Cant really figure out why its missing a ")"?
Hi Mikael
try this code, it's working for me:
Thanks,
Alex
Hi Mikael
Did you solve the issue? Share with our community, please )
Thanks,
Alex
Here is the code of the macro that is now running and working on my site:
Tested to also work with iphone and to scale properly.
is working on a reply...