离子3音频直播比直播电台

时间:2017-09-03 18:43:32

标签: angular typescript ionic2 cordova-plugins ionic3

我正在开发一个带有ionic3的无线电台移动应用程序,在使用离线3中的StreamingMedia插入整合直播后,比无线电台主流慢1分钟,请帮忙吗?

Radio.ts

 export class RadioPlayer {
  url:string;
  stream:any;
  promise:any;
   constructor() {
   this.url = "http://104.247.79.188:8000/kfm";
   this.stream = new Audio(this.url);
 };
 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();
};

}

appComponent.ts

 import { Component, ViewChild } from '@angular/core';
 import { Platform, MenuController, Nav } from 'ionic-angular';
 import {RadioPlayer} from './radio/radio';
    @Component({
  templateUrl: 'app.html',
  providers: [RadioPlayer]
})
export class MyApp {
  constructor(player: RadioPlayer) 
{
    this.player = player;
    this.play();
 }
 play() {
    this.player.play().then(() => {
      console.log('Playing');
    });
  }
  pause() {
    this.player.pause();
  }
}

1 个答案:

答案 0 :(得分:0)

我想建议使用Native Streaming Media插件。因为它是原生的希望你的缓慢会消失。

  

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

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

Git Repo