简体   繁体   English

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

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

The MP3 live audio stream in our Ionic 3 app works correctly with ionic serve , but running it on a device it gives net::ERR_CONNECTION_REFUSED on Android and NSURLConnection finished with error - code -1100 on iOS.我们的 Ionic 3 应用程序中的 MP3 实时音频流与ionic serve一起正常工作,但在设备上运行它会在 Android 上提供net::ERR_CONNECTION_REFUSEDNSURLConnection finished with error - code -1100在 iOS 上NSURLConnection finished with error - code -1100

My player service:我的播放器服务:

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();
    };
}

Replacing the live stream URL with an URL to a MP3 file (eg https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3 ) works.用指向 MP3 文件的 URL(例如https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3 )替换直播流 URL 有效。 Probably the problem has something to do with the live stream having no length, but I can't figure out how to solve that.问题可能与没有长度的直播有关,但我不知道如何解决。

I highly recommend using Native Streaming Media Plugin here.我强烈建议在这里使用 原生流媒体插件 Since some of the web solutions are not working properly on native devices.由于某些 Web 解决方案在本机设备上无法正常工作。

This plugin allows you to stream audio and video in a fullscreen, native player on iOS and Android.此插件允许您在 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