2017-03-28 27 views
0

我正在使用離子插件cordova-plugin-mediaIonic 2媒體插件

component.ts

import {Page} from 'ionic-framework/ionic'; 

declare var Media:any; 

@Page({ 
    templateUrl: 'build/pages/settings/offline.html', 
}) 
export class TestPage { 
    audio; 
    constructor() { 
     this.audio = new Media('https://firebasestorage.googleapis.com/v0/b/apartments-ea9e5.appspot.com/o/Loud-Ringtone-11-Emergency-Alert.mp3?alt=media&token=7d67b437-e96b-484e-bd97-008106a06dcb'); 
     this.audio.play(); 
    } 
} 

我怎麼能播放和停止音頻文件?

我目前收到此錯誤。

ReferenceError: Media is not defined .

回答

0

您沒有安裝您的科爾多瓦插件

ionic plugin add cordova-plugin-media 

注意,以測試它在您的手機上。

你可以尋找完整的API這裏https://github.com/apache/cordova-plugin-media

但audio.play玩,audio.stop停止& audio.pause暫停。

+0

謝謝你的回覆。第一次只播放音頻文件。第二次音頻文件不能播放爲什麼..你可以幫我 – ANISUNDAR

+0

我收到這個錯誤。我用this.audio.stop();和this.audio.play()。不能讀屬性'play'的undefined – ANISUNDAR

0

確保您在設備或模擬器上運行應用程序,因爲瀏覽器不支持許多cordova插件。

+0

謝謝你的回覆。第一次只播放音頻文件。第二次音頻文件不能播放爲什麼..你能幫我嗎 – ANISUNDAR