繁体   English   中英

HTML5 音频实时流在设备中拒绝连接

[英]HTML5 Audio live stream gives connection refused in device

我们的 Ionic 3 应用程序中的 MP3 实时音频流与ionic serve一起正常工作,但在设备上运行它会在 Android 上提供net::ERR_CONNECTION_REFUSEDNSURLConnection finished with error - code -1100在 iOS 上NSURLConnection finished with error - code -1100

我的播放器服务:

import {Injectable} from '@angular/core';

@Injectable()
export class PlayerService {
    stream: any;
    promise: any;

    constructor() {
        this.initLiveStream();
    }

    initLiveStream() {
        this.stream = new Audio('http://audio-mp3.ibiblio.org:8000/wcpe.mp3');
    }

    play() {
        this.stream.play();

        this.promise = new Promise((resolve,reject) => {
            this.stream.addEventListener('playing', () => {
                resolve(true);
            });

            this.stream.addEventListener('error', () => {
                reject(false);
            });
        });

        return this.promise;
    };

    pause() {
        this.stream.pause();
    };
}

用指向 MP3 文件的 URL(例如https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3 )替换直播流 URL 有效。 问题可能与没有长度的直播有关,但我不知道如何解决。

我强烈建议在这里使用 原生流媒体插件 由于某些 Web 解决方案在本机设备上无法正常工作。

此插件允许您在 iOS 和 Android 上的全屏原生播放器中流式传输音频和视频。

ionic cordova plugin add cordova-plugin-streaming-media
npm install --save @ionic-native/streaming-media

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM