【发布时间】:2018-02-12 02:00:02
【问题描述】:
我正在使用 ionic3 开发一个电台移动应用程序,在使用 ionic3 中的 StreamingMedia 插件集成直播后,比电台主流慢 1 分钟,请帮忙?
无线电.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();
}
}
【问题讨论】:
-
你能展示一些你的
code吗? -
radio.ts 导出类 RadioPlayer { url:string;流:任何;承诺:任何;构造函数() { this.url = "/*9"; this.stream = new Audio(this.url); };播放() { this.stream.play(); this.promise = new Promise((resolve,reject) => { this.stream.addEventListener('playing', () => { resolve(true); }); this.stream.addEventListener('error', () => { 拒绝(假); }); });返回 this.promise; }; pause() { this.stream.pause(); }; }
-
你能看懂吗?请使用
code格式将其放入您的问题中? -
对不起,上面的代码
标签: angular typescript ionic2 cordova-plugins ionic3