在通过shoutcast实现音频API方面遇到了挑战,目前正在使用Ionic开发流式广播应用程序。当我使用来自shoutcase的音频API进行流式播放时,它拒绝播放音频。
对此有什么帮助吗?谢谢
//playerservice
import { Injectable } from '@angular/core';
import { Media, MediaObject } from '@ionic-native/media';
import { LoadingController, Platform } from 'ionic-angular';
@Injectable()
export class PlayerServiceProvider {
// This controls the alternating play and pause images and function
play: boolean = true;
// Property “radio” for the instance of the MediaObject for the Media plugin
radio: MediaObject
constructor(private media: Media, private platform: Platform, public loadingCtrl: LoadingController) {
this.platform.ready().then(() => {
this.radio = this.media.create('http://yp.shoutcast.com/sbin/tunein-station.m3u?id=862132'); // Insert your own stream URL here.
this.radio.play();
});
}
// Function to play the audio stream
playAudio() {
//Loading Spinner Configuration
const loading = this.loadingCtrl.create({
content: 'Loading stream...',
spinner: 'crescent',
showBackdrop: false,
cssClass: 'spin' // This class is defined in the app.scss file
});
loading.present();
setTimeout(() => {
loading.dismiss();
}, 4000);
//End of Loading Spinner Configuration
// This controls the alternating play and pause images and function
this.play = false;
}
// Function to stop the audio stream
stopAudio() {
this.radio.stop();
// This controls the alternating play and pause images and function
this.play = true;
}
}