uni-app 安卓华为直播流控件预览快照2次后闪退

uni-app 安卓华为直播流控件预览快照2次后闪退

产品分类 HBuilderX版本号 手机系统 手机系统版本号 手机厂商 手机机型 打包方式
HTML5+ 3.2.3 Android Android 10 华为 nova5i Mate10 云端
示例代码:

```vue
<template>
<div class="real_time_extract_img">
<x-header :left-options="{backText: '', preventGoBack: true}" [@on-click-back](/user/on-click-back)="onBack">测试</x-header>
<div class="player" id="playerRef"></div>
<button [@click](/user/click)="snapshot">快照</button>
</div>
</template> 
<script>
import { XHeader } from 'vux';
export default {
components: {XHeader},
data() {
return {
pusher: null
};
},
mounted() {
this.init();
},
methods: {
init() {
if (!window.plus) return;
document.addEventListener('plusready', this.initPusher(), false);
},
initPusher() {
this.pusher = new window.plus.video.LivePusher('playerRef', {
mode: 'HD',
position: 'static',
top: '47px',
with: '100%',
height: '300px',
bottom: '46px',
muted: true
});
window.plus.webview.currentWebview().append(this.pusher);
this.preview();
// 监听状态变化事件
this.pusher.addEventListener('statechange', function(e) {
console.log('statechange: ' + JSON.stringify(e));
}, false);
// 监听网络状态变化事件
this.pusher.addEventListener('netstatus', function(e) {
console.log('netstatus: ' + JSON.stringify(e));
}, false);
// 监听错误事件
this.pusher.addEventListener('error', function(e) {
console.log('error: ' + JSON.stringify(e));
}, false);
},
preview() {
this.pusher && this.pusher.preview();
},
snapshot() { // 快照
this.pusher && this.pusher.snapshot((e) => {
window.plus.nativeUI.alert('snapshot success: ' + JSON.stringify(e));
}, (e) => {
window.plus.nativeUI.alert('snapshot error: ' + JSON.stringify(e));
});
},
close() {
this.pusher && this.pusher.close();
},
onBack() {
this.$router.back();
this.close();
}
}
};
</script> 

<style lang="scss" scoped>
.real_time_extract_img{
box-sizing: border-box;
width: 100vw;
height: 100vh;
overflow: hidden;
padding-top: 47px;
.player{
height: 300px;
}
}
</style>

操作步骤:

  • 创建了一个直播流控件,然后预览,点击按钮获取快照,第一次成功了,然后点击第二次获取快照,然后应用就闪退了。

预期结果:

  • 每一次点击获取快照都能成功获取。

实际结果:

  • 第二次获取快照,应用闪退。


bug描述:
snapshot() { // 快照
this.pusher && this.pusher.snapshot((e) => {
window.plus.nativeUI.alert('snapshot success: ' + JSON.stringify(e));
}, (e) => {
window.plus.nativeUI.alert('snapshot error: ' + JSON.stringify(e));
});
},
安卓调用第一次成功后,第二次应用直接闪退

更多关于uni-app 安卓华为直播流控件预览快照2次后闪退的实战教程也可以访问 https://www.itying.com/category-93-b0.html

12 回复

根据新发的ask地址:https://ask.dcloud.net.cn/question/147593
提供的示例,我复现了闪退的问题,并做了相关处理。
其他问题我无法复现,更具体的回复查看新的ask

更多关于uni-app 安卓华为直播流控件预览快照2次后闪退的实战教程也可以访问 https://www.itying.com/category-93-b0.html


解决了吗?我现在也出现这个问题

我还发现一个问题就是快照拍出来的图片方向不对

我的解决方法是createLivePusher重置

我现在是预览图片返回时会闪退,而且快照的清晰度不行

解决了吗,我也出现了这个问题

一年了,问题还有,,,,,,

帮忙提供一下可以复现问题的示例。 我现在试试

回复 phoeniix: 我试试

回复 DCloud_Android_DQQ: 这个问题解决没有,vue页面会闪退

根据你提供的代码和问题描述,这很可能是一个内存管理问题。在uni-app的HTML5+环境中,直播流控件(LivePusher)的快照功能在安卓设备上可能存在内存泄漏或资源未正确释放的问题。

从代码分析来看,每次调用snapshot()方法时,系统需要分配内存来处理图像捕获。第一次调用成功后,相关资源可能没有被完全释放,导致第二次调用时内存不足而引发应用崩溃。

建议尝试以下解决方案:

  1. 添加延迟调用:在快照操作之间添加适当的延迟,给系统足够的时间释放资源。
snapshot() {
    if (this.isSnapshotting) return;
    this.isSnapshotting = true;
    
    this.pusher && this.pusher.snapshot((e) => {
        window.plus.nativeUI.alert('snapshot success: ' + JSON.stringify(e));
        setTimeout(() => {
            this.isSnapshotting = false;
        }, 1000);
    }, (e) => {
        window.plus.nativeUI.alert('snapshot error: ' + JSON.stringify(e));
        this.isSnapshotting = false;
    });
}
  1. 手动释放资源:在每次快照后尝试重新初始化控件
async snapshot() {
    if (!this.pusher) return;
    
    this.pusher.snapshot((e) => {
        window.plus.nativeUI.alert('snapshot success: ' + JSON.stringify(e));
        // 重新初始化pusher
        this.reinitPusher();
    }, (e) => {
        window.plus.nativeUI.alert('snapshot error: ' + JSON.stringify(e));
    });
}

reinitPusher() {
    if (this.pusher) {
        this.pusher.close();
        this.pusher = null;
    }
    setTimeout(() => {
        this.initPusher();
    }, 500);
}
回到顶部