Back Button In front of page

Welcome! Forums Unity Plugins In-App Web Browser Back Button In front of page

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #266
    Zeldarck
    Participant

    Hi,

    I use the plugin in the goal to do a full screen player of youtube video, (to host the video/subtitle on youtube).
    To display the video I use this html:
    <div style='position:absolute;left:0;right:0;top:0px;bottom:0;overflow:auto;'><iframe id=\"ytplayer\" type=\"text/html\" width=\"640\" height=\"360\" src=\"http://www.youtube.com/embed/kQye2uNafk0?autoplay=1&controls=0&rel=0&showinfo=0&cc_load_policy=1&hl=ru&fs=1\" frameborder=\"0\" style=\"margin:0px;padding:0px;\"/></div>
    I would like to display the back button in front of the video (because Iphone don’t have back button :'( ). Is it possible by any mean ? Or I have to create a custom html button wich call a js to close the browser? And for close with js, is it a direct function, or I have to use

    function sendMessageToUnity(message) {
    if (isIOS()) {
    appendIframeWithURL('inappbrowserbridge://' + message);
    } else if (isAndroid()){
    UnityInAppBrowser.sendMessageFromJS(message);
    }
    }

    To call a unity function wich close the Browser?

    #268
    Zeldarck
    Participant

    Ok, I have do that :

    <script>
    
    var userAgent = navigator.userAgent || navigator.vendor || window.opera;
    function isIOS() {
    if (/iPad|iPhone|iPod/.test(userAgent) && !window.MSStream) {
    return true;
    } else {
    return false;
    }
    }
    function isAndroid() {
    return (/android/i.test(userAgent));
    }
    In
    
    function sendMessageToUnity(message) {
    if (isIOS()) {
    appendIframeWithURL('inappbrowserbridge://' + message);
    } else if (isAndroid()){
    UnityInAppBrowser.sendMessageFromJS(message);
    }
    }
    </script>
    
    <div style='position:absolute;left:0;right:0;top:0px;bottom:0;overflow:auto;'>
    <button type="button" onclick="sendMessageToUnity('message')"  style = "        
      border-radius: 8px; border: none;    padding: 0em 1em;
    
        color: white;
        font-size: 16px;position: absolute;top: 10px;left: 10px;background-color: #000000;height: 30px;">X</button>
    
    <iframe id="ytplayer" type="text/html" width="640" height="360"
      src="http://www.youtube.com/embed/kQye2uNafk0?autoplay=1&controls=0&rel=0&showinfo=0&cc_load_policy=1&hl=ru&fs=1"
      frameborder="0" style="margin:0px;padding:0px;"/>
    </div>
    
    void Start(){
            InAppBrowserBridge bridge = FindObjectOfType<InAppBrowserBridge>();
            bridge.onJSCallback.AddListener((string s) => OnCloseBrowser());
    }
    
        public void OnCloseBrowser()
        {
            StartCoroutine(CloseYouTubeVideo());       
        }
    
        protected IEnumerator CloseYouTubeVideo()
        {
            InAppBrowser.CloseBrowser();
            Screen.orientation = ScreenOrientation.Portrait;
            while (Screen.currentResolution.height > Screen.currentResolution.width)
            {
                yield return null;
            }
    
            UICommander.ShowAll();
    
        }
    
        protected IEnumerator PlayYoutubeVideo()
        {
            yield return new WaitForSeconds(1);
    
            UICommander.HideAll();
    
            Screen.orientation = ScreenOrientation.Landscape;
            while (Screen.currentResolution.height > Screen.currentResolution.width)
            {
                yield return null;
            }
    
            InAppBrowser.DisplayOptions displayOption = new InAppBrowser.DisplayOptions();
            displayOption.displayURLAsPageTitle = false;
            displayOption.hidesTopBar = true;
    
            InAppBrowser.OpenLocalFile("test.html", displayOption);
        }
    

    still not very beautiful, if you have a better mean, I’m open to 🙂

    • This reply was modified 4 years, 3 months ago by Zeldarck.
    #271
    PiotrPiotr
    Keymaster

    Looks good 🙂

    #291
    Zeldarck
    Participant

    I will begin the debug, but this code didn’t work on IOS (but very well in android)

    #292
    Zeldarck
    Participant

    So, the message is effectivily send with

    function sendMessageToUnity(message) {
    if (isIOS()) {
    appendIframeWithURL('inappbrowserbridge://' + message);
    } else if (isAndroid()){
    UnityInAppBrowser.sendMessageFromJS(message);
    }
    }

    but my callback is not call:

     
            bridge.onJSCallback.AddListener((string s) => OnCloseBrowser());
    
       public void OnCloseBrowser()
        {
            StartCoroutine(CloseYouTubeVideo());       
        }
    
    
    #293
    PiotrPiotr
    Keymaster

    what’s appendIframeWithURL ?

    #294
    Zeldarck
    Participant

    Ok I am idiot, I forgot to c/c the code of this function from your read me, I will try with, sorry ><

    #295
    Zeldarck
    Participant

    So it’s work 🙂

    #296
    PiotrPiotr
    Keymaster

    Cool. btw that Javascript code from readme is just example, I didn’t assume people will actually use it in production 🙂

Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.