webview加载的网页的音乐在场景退出后继续播放

webview加载的网页音乐,在退出后webview所在的场景后,音乐继续播放。
这个场景已经勾选了自动释放。
在场景切换的回调里,也加了webview的destory,但是场景切换后,看不到destory后面的log,也没有报错,音乐也还在继续播放。
请问是bug么?还是使用方式的问题呢?代码如下:
cc.director.loadScene(“scene/06-h5”, function(webview) {
console.log(‘webview node destory start’);
webview.node.parent = null;
webview.node.destroy();
console.log(‘webview node destory end’);//这个没执行
}.bind(this, this.webview));

版本1.61,iphone6真机。

为什么场景切换后webview加载的资源没有销毁呢?
主动执行webview的destory,没有报错,也没有效果,后面的log也没执行,这是什么原因呢?

这个算资源释放问题?webview问题?音频问题?

求关注。

自己顶。

自己顶。

这个要测一下,是不是只有真机上才会出现呢?预览上可以吗?

webview只可以真机啊,我用的mac电脑

预览版本也可以吧… 那行,我测试一下

具体的操作是

2 个场景一个放着 webView,然后切换到另一个场景时做下列代码操作,是这样的吗?

cc.director.loadScene("scene/06-h5", function(webview) {
    console.log('webview node destory start');
    webview.node.parent = null; 
    webview.node.destroy();
    console.log('webview node destory end');//这个没执行
}.bind(this, this.webview));

是这样的,多谢:)

能否给我一个网页音乐地址?

我给你发qq吧

场景勾选的的自动释放,延迟加载两个选项

修复了,如果比较急可以自定义,下面是 PR 链接:

https://github.com/cocos-creator/cocos2d-x-lite/pull/782

2赞

多谢@knox,我等下个版本的binary吧,下个版本会合并这个修复吧

嗯 asd

好的,耐心等待:)

刚才测试了1.61正式版,这个问题还存在,请问这个修复合并到1.61正式版本了么?
binary方式。

你看一下 ‘UIWebView-inl.h’ 这个文件里面是否有 cleanup 函数

看这样,是没有合并吧?
/// @cond DO_NOT_SHOW

#include “ui/UIWebView.h”
#include “platform/CCGLView.h”
#include “base/CCDirector.h”
#include “platform/CCFileUtils.h”

NS_CC_BEGIN
namespace experimental{
namespace ui{

    WebView::WebView()
    : _impl(new WebViewImpl(this)),
    _onJSCallback(nullptr),
    _onShouldStartLoading(nullptr),
    _onDidFinishLoading(nullptr),
    _onDidFailLoading(nullptr)
    {
    }

    WebView::~WebView()
    {
        CC_SAFE_DELETE(_impl);
    }

    WebView *WebView::create()
    {
        auto webView = new(std::nothrow) WebView();
        if (webView && webView->init())
        {
            webView->autorelease();
            return webView;
        }
        CC_SAFE_DELETE(webView);
        return nullptr;
    }

    void WebView::setJavascriptInterfaceScheme(const std::string &scheme)
    {
        _impl->setJavascriptInterfaceScheme(scheme);
    }

    void WebView::loadData(const cocos2d::Data &data,
                           const std::string &MIMEType,
                           const std::string &encoding,
                           const std::string &baseURL)
    {
        _impl->loadData(data, MIMEType, encoding, baseURL);
    }

    void WebView::loadHTMLString(const std::string &string, const std::string &baseURL)
    {
        _impl->loadHTMLString(string, baseURL);
    }

    void WebView::loadURL(const std::string &url)
    {
        _impl->loadURL(url);
    }

    void WebView::loadFile(const std::string &fileName)
    {
        _impl->loadFile(fileName);
    }

    void WebView::stopLoading()
    {
        _impl->stopLoading();
    }

    void WebView::reload()
    {
        _impl->reload();
    }

    bool WebView::canGoBack()
    {
        return _impl->canGoBack();
    }

    bool WebView::canGoForward()
    {
        return _impl->canGoForward();
    }

    void WebView::goBack()
    {
        _impl->goBack();
    }

    void WebView::goForward()
    {
        _impl->goForward();
    }

    void WebView::evaluateJS(const std::string &js)
    {
        _impl->evaluateJS(js);
    }

    void WebView::setScalesPageToFit(bool const scalesPageToFit)
    {
        _impl->setScalesPageToFit(scalesPageToFit);
    }

    void WebView::draw(cocos2d::Renderer *renderer, cocos2d::Mat4 const &transform, uint32_t flags)
    {
        cocos2d::ui::Widget::draw(renderer, transform, flags);
        _impl->draw(renderer, transform, flags);
    }

    void WebView::setVisible(bool visible)
    {
        Node::setVisible(visible);
        if (!visible || isRunning())
        {
            _impl->setVisible(visible);
        }
    }

    void WebView::onEnter()
    {
        Widget::onEnter();
        if(isVisible())
        {
            _impl->setVisible(true);
        }
    }

    void WebView::onExit()
    {
        Widget::onExit();
        _impl->setVisible(false);
    }
    
    void WebView::setBounces(bool bounces)
    {
      _impl->setBounces(bounces);
    }
    
    cocos2d::ui::Widget* WebView::createCloneInstance()
    {
        return WebView::create();
    }

    void WebView::copySpecialProperties(Widget* model)
    {
        WebView* webView = dynamic_cast<WebView*>(model);
        if (webView)
        {
            this->_impl = webView->_impl;
            this->_onShouldStartLoading = webView->_onShouldStartLoading;
            this->_onDidFinishLoading = webView->_onDidFinishLoading;
            this->_onDidFailLoading = webView->_onDidFailLoading;
            this->_onJSCallback = webView->_onJSCallback;
        }
    }

    void WebView::setOnDidFailLoading(const ccWebViewCallback &callback)
    {
        _onDidFailLoading = callback;
    }

    void WebView::setOnDidFinishLoading(const ccWebViewCallback &callback)
    {
        _onDidFinishLoading = callback;
    }

    void WebView::setOnShouldStartLoading(const std::function<bool(WebView *sender, const std::string &url)> &callback)
    {
        _onShouldStartLoading = callback;
    }

    void WebView::setOnJSCallback(const ccWebViewCallback &callback)
    {
        _onJSCallback = callback;
    }

    std::function<bool(WebView *sender, const std::string &url)> WebView::getOnShouldStartLoading()const
    {
        return _onShouldStartLoading;
    }

    WebView::ccWebViewCallback WebView::getOnDidFailLoading()const
    {
        return _onDidFailLoading;
    }

    WebView::ccWebViewCallback WebView::getOnDidFinishLoading()const
    {
        return _onDidFinishLoading;
    }

    WebView::ccWebViewCallback WebView::getOnJSCallback()const
    {
        return _onJSCallback;
    }

} // namespace ui

} // namespace experimental
} //namespace cocos2d

/// @endcond