2017-10-18 163 views
2

我们的Io​​nic 3应用中的MP3直播音频流与ionic serve正常工作,但在Android设备上运行net::ERR_CONNECTION_REFUSED,在iOS设备上运行NSURLConnection finished with error - code -1100HTML5音频直播流让设备中的连接被拒绝

我的播放器服务:

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

与URL更换现场直播的网址为MP3文件(例如https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3)的作品。可能这个问题与没有长度的直播流有关,但我无法弄清楚如何解决这个问题。

回答

1

我强烈建议您在这里使用Native Streaming Media Plugin。由于某些网络解决方案在本机设备上无法正常工作。

This plugin allows you to stream audio and video in a fullscreen, native player on iOS and Android.

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

我喜欢使用本地玩家的想法,但我的应用程序使其完全阻断的功能,因为它是全屏幕。但更重要的是:mp3文件播放,但实时流给出'媒体播放器错误:未知(1)-1005' – JanP

+0

当你在本地播放器(插件)播放实时流时出现上述错误? – Sampath

+1

是的,它的确如此。但是我发现问题与流而不是应用有关。我尝试了荷兰非常受欢迎的广播电台(http://icecast.omroep.nl/3fm-bb-mp3),它可以在上面的代码中工作(即使使用HTML5解决方案)。 感谢您的回答。 – JanP