首页 > 解决方案 > Ionic 4 Radio Streaming App 与 icecast2 背景模式和 Audio() 网络功能

问题描述

实际上,我有一个带有背景模式插件和音频的 Audio() HTML5 函数的 ionic 4 实现。(音频源是带有 aacplus 的 icecast 2.4.4 服务器)。

在我尝试使用 Cordova Media 插件但不支持 icecast 之前。

我有一些问题:

当手机未连接电池(或充电)时,如果手机被阻塞,则 5 分钟后音频停止,如果未连接(充电)但您正在使用该应用程序,则不会。

我的代码是这样的:

 this.global.streamingAndroid = new Audio();
 this.global.streamingAndroid.controls = true;
 this.global.streamingAndroid.src = this.streamingUrl+'&vapp='+Math.random();
 this.global.streamingAndroid.load();
 this.global.streamingAndroid.play();

 ...


 this.backgroundMode.enable();
 this.backgroundMode.setDefaults({ silent: true });
 // this.backgroundMode.disableWebViewOptimizations();
 // this.backgroundMode.disableBatteryOptimizations();
 this.backgroundMode.on('activate').subscribe(() => {
      this.backgroundMode.disableWebViewOptimizations();
      this.backgroundMode.disableBatteryOptimizations();
 });

标签: ionic4audio-streamingicecastbackground-modecordova-media-plugin

解决方案


推荐阅读