Copied to clipboard

Flag this post as spam?

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


  • Cyrus Hiatt 9 posts 72 karma points
    Dec 22, 2023 @ 12:18
    Cyrus Hiatt
    0

    Why will this code not work in my production environment?

    The code below works perfectly in Dev and Stage environment but not Production. Can provide more of the code if helps.

    @functions{
        private bool isSafari
        {
            get
            {
                var userAgent = HttpContext.Current.Request.UserAgent;
                return !string.IsNullOrEmpty(userAgent) && userAgent.Contains("Safari") && userAgent.Contains("Mac OS");
            }
        }
    }
    
  • Huw Reddick 1929 posts 6717 karma points MVP 2x c-trib
    Dec 22, 2023 @ 14:52
    Huw Reddick
    0

    Are you getting any errors?

  • Cyrus Hiatt 9 posts 72 karma points
    Dec 22, 2023 @ 16:49
    Cyrus Hiatt
    0

    I am not seeing any script errors in the console if that is what you are referring to. Should I check anywhere else?

    What I am trying to do is playing an mp4 file if the browser is Safari, otherwise a Webm should play.

     @if (Model.value.mp4 != null && Model.value.mp4.value != null)
        {
            var mp4Media = Umbraco.Media((string)Model.value.mp4.value);
            if (isSafari && mp4Media != null) // Use the isSafari variable here
            {
                <video autoplay loop muted playsinline style="width: 100%; @styleValue" title="@Model.value.altText.value">
                    <source src="@mp4Media.Url"
                            type="video/mp4"
                            style="@styleValue"
                            class="@(Model.value.mediaClass != null ? Model.value.mediaClass.value : string.Empty)" />
                    <source src="@image.Url"
                            type="video/webm"
                            style="@styleValue"
                            class="@(Model.value.mediaClass != null ? Model.value.mediaClass.value : string.Empty)" />
                    Your browser does not support the video.
                </video>
            }
            else
            {
                <video autoplay loop muted playsinline style="width: 100%; @styleValue" title="@Model.value.altText.value">
                    <source src="@image.Url"
                            type="video/webm"
                            style="@styleValue"
                            class="@(Model.value.mediaClass != null ? Model.value.mediaClass.value : string.Empty)" />
                    <source src="@mp4Media.Url"
                            type="video/mp4"
                            style="@styleValue"
                            class="@(Model.value.mediaClass != null ? Model.value.mediaClass.value : string.Empty)" />
                    Your browser does not support the video.
                </video>
            }
        }
    
  • Huw Reddick 1929 posts 6717 karma points MVP 2x c-trib
    Dec 22, 2023 @ 17:11
    Huw Reddick
    0

    What exactly happens in prod? Is anything rendered?

  • Cyrus Hiatt 9 posts 72 karma points
    Dec 25, 2023 @ 10:10
    Cyrus Hiatt
    0

    The webm plays first in both Safari and Chrome. In staging and dev, the mp4 plays first in Safari and the webm plays first in chrome.

  • Huw Reddick 1929 posts 6717 karma points MVP 2x c-trib
    Dec 26, 2023 @ 16:37
    Huw Reddick
    0

    Are you able to log what it thinks the user agent is?

  • Cyrus Hiatt 9 posts 72 karma points
    Jan 02, 2024 @ 07:26
    Cyrus Hiatt
    0

    Yes, I am also using a browser testing tool/and asked a colleague with a macbook to view the video on the page and the code is not working as it should.

Please Sign in or register to post replies

Write your reply to:

Draft