gpt4 book ai didi

iOS 应用程序卡住,在 webview 中加载视频时不会崩溃

转载 作者:可可西里 更新时间:2023-11-01 06:16:41 25 4
gpt4 key购买 nike

我有一个 iPad 应用程序是使用名为 OpenPlug 的第 3 方工具开发的,它将 AS3 转换为 C++,然后从那里导出到 iOS。 (只是想指出这不是我编写的在 XCode 中使用 Obj-C 的“ native ”应用程序,我编写了 AS3)

现在我有了这个 iPad 应用程序,它可以在幻灯片中显示图片和视频。对于视频,我使用加载 HTML 页面的 WebView,我在其中将视频对象的 src 属性更改为下载到我的应用程序存储的视频文件的位置。这工作正常,只是应用程序在运行几个小时 (3-6) 时会卡住。

我搜索了这个问题并尝试了 iOS Safari memory leak when loading/unloading HTML5 <video> 中的解决方案但这对我来说似乎没有任何改变。

由于应用程序卡住(就在 HTML 页面需要加载视频之前)并且没有崩溃,这意味着什么?我需要销毁视频对象吗?首先,我为每个视频创建了一个新的 WebView,但现在我重新使用了 webview,只是更改了 src 属性,但这对我也没有帮助。

任何人都可以阐明这一点吗? OpenPlug 已停止服务,不再提供任何支持,但我认为它更像是 iPad 上的 WebView /视频问题 (?)

重要提示:应用程序卡住但我的 iPad 没有。该应用程序不会生成崩溃报告,也不会再执行任何代码(也没有痕迹)。当我按下 iPad 上的主屏幕按钮并按下应用程序图标时,应用程序会重新启动。

这是我的 HTML 页面的代码,每次需要开始播放新视频时都会刷新它 (webview.location = ...)

<html>
<head>
<script>
function videoEndedHandler(){
var video = document.getElementById("videoPlayer");
video.src = "";
video.load();
window.location.hash = "ended";
}

function videoErrorHandler(){
window.location.hash = "error";
var video = document.getElementById("videoPlayer");
video.src = "";
video.load();
}

var loop;
function setup(){
var video = document.getElementById("videoPlayer");
video.addEventListener("error", videoErrorHandler,false);
video.addEventListener("ended", videoEndedHandler,false);
video.load();
video.play();
startHashLoop();
}

function startHashLoop(){
if(window.location.hash == "#touched"){
setAsPaused();
}

if(window.location.hash == "#paused"){
//check image
testImage("shouldResume.png?nocache=" + Math.random());
}


if(window.location.hash == "#resume"){
var video = document.getElementById("videoPlayer");
video.play();
}

loop = setTimeout(hashLoop,500);
}

function testImage(url) {
var img = new Image;
img.addEventListener("load",isGood);
img.addEventListener("error",isBad);

img.src = url;
}

function isGood() {
window.location.hash = "resume";
}

function isBad() {
//alert("Image does not exist");
}


function hashLoop(){
startHashLoop();
}

function setAsTouched(){
window.location.hash = "touched";
}

function setAsPaused(){
var video = document.getElementById("videoPlayer");
video.pause();
window.location.hash = "paused";
}
</script>
</head>

<body onload="setup();" style="background-color:#000000;">
<a href="javascript:setAsTouched()" style="top:0;left:0;position:absolute;z-index:1;color:#FF0000;border:0px solid red;width:100%;height:100%;display:block;"></a>
<video id="videoPlayer" style="top:0;left:0;position:absolute;" width="100%" height="100%" preload="auto" src="##VIDEO_URL##" autoplay="autoplay" webkit-playsinline />

</body>
</html>

最佳答案

如果您发布整个代码会很有帮助,但我认为它会卡住,因为您在主线程中从 Web 加载视频,该线程还负责重绘 UI。通过在您的线程中加载大型视频,您的 UI 也会卡住。

我建议将执行视频加载的代码移动到单独的线程中(如果您使用的是 iOS5,请使用 block )。

关于iOS 应用程序卡住,在 webview 中加载视频时不会崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10974987/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com