Stop video in UIWebView

前端 未结 6 1701
别那么骄傲
别那么骄傲 2020-12-28 21:29

In my iPad App I have a modal view (UIViewController with modal presentation style UIModalPresentationPageSheet)

Inside the view is a UIWeb

相关标签:
6条回答
  • 2020-12-28 21:37

    In Swift method :

    override public func viewDidDisappear(animated: Bool) {
        super.viewDidAppear(animated)
        self.webView.loadHTMLString("", baseURL: nil)
    }
    

    thanks @alloc_iNit

    0 讨论(0)
  • 2020-12-28 21:38

    Do integrate following code to sort out the problem.

        -(void)viewWillDisappear:(BOOL)animated
        {
            [webView loadHTMLString:nil baseURL:nil];
        }
    
    0 讨论(0)
  • 2020-12-28 21:38

    Swift 4

    //  Halt anything in progress
    (contentViewController as! WebViewController).webView.loadHTMLString("Yoink://", baseURL: nil)
    

    needed in a windowController's windowShouldClose() method when I close a window

    0 讨论(0)
  • 2020-12-28 21:41

    Also you can try to pause video:

    NSString *script = @"var videos = document.querySelectorAll(\"video\"); for (var i = videos.length - 1; i >= 0; i--) { videos[i].pause(); };";
    [webView stringByEvaluatingJavaScriptFromString:script];
    
    0 讨论(0)
  • 2020-12-28 21:44

    I saw there are many suggestions with loading blank page. That is really bad approach.

    It will cause your webview to be blank if, let say you push you another view on top of it.

    Most simple solution is to reload the view with:

    Swift

    webView.reload()
    

    Obj-C

    [webView reload]
    
    0 讨论(0)
  • 2020-12-28 21:58

    Use the following javascript in WKWebview to pause the video player in swift

    wkWebView.evaluateJavaScript("var videos = document.querySelectorAll(\"video\"); for (var i = videos.length - 1; i >= 0; i--) { videos[i].pause(); };", completionHandler: nil)
    

    to stop the video player use:

    wkWebView.loadHTMLString("", baseURL: nil)
    
    0 讨论(0)
提交回复
热议问题