【发布时间】:2018-06-27 08:23:04
【问题描述】:
有一种情况,我在 firebase 存储中有一些音频,需要下载到手机本地内存,所以当我启动应用程序时,它应该检查本地内存中是否有任何音频,如果存在,它会播放,否则从 firebase 存储下载。
任何人都可以帮助我这个 ionic 3 和 firebase 吗?
我有这个连接
<script src="https://www.gstatic.com/firebasejs/5.0.4/firebase.js"></script>
<script >
var config = {
apiKey: "AIzaSyAg6dBk2BJ-DlFHm0f0G-9XpIcjb-Zl7DY",
authDomain: "helloworld-4e6e6.firebaseapp.com",
databaseURL: "https://helloworld-4e6e6.firebaseio.com",
projectId: "helloworld-4e6e6",
storageBucket: "helloworld-4e6e6.appspot.com",
messagingSenderId: "386944915967"
};
firebase.initializeApp(config);
</script>
这是我的.ts 文件
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { AboutPage } from '../about';
import { FileTransfer, FileUploadOptions, FileTransferObject } from '@ionic-
native/file-transfer';
import { NativeAudio } from '@ionic-native/native-audio';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
bleep = new Audio();
constructor() {
}
download() {
const url = 'https://firebasestorage.googleapis.com/v0/b/helloworld-
4e6e6.appspot.com/o/audio%2Fp10_1.mp3?alt=media&token=12bf3400-17a7-4cf9-
b862-973707a3164e';
fileTransfer.download(url, this.file.dataDirectory +
'test.mp3').then((entry) => {
console.log('download complete: ' + entry.toURL());
}, (error) => {
console.log('Error during download: '+error);
});
}
wajid()
{
const fileTransfer: FileTransferObject = this.transfer.create();
this.download();
this.nativeAudio.preloadSimple('uniqueId1', this.file.dataDirectory +
'test.mp3').then((res) => {
console.log('Mp3 ready');
}, (error) => {
console.log("Some error during load the audio "+error);
});
this.nativeAudio.play('uniqueId1').then((onSuccess)=>{
console.log('Mp3 reproduced ok');
}, (onError)=>{
console.log("Some error during reproduce of the audio "+onError);
});
// can optionally pass a callback to be called when the file is done
playing
//this.nativeAudio.play('uniqueId1', () => console.log('uniqueId1 is
done playing'));
}
这是我的html按钮
<div class= "sections" style="width: 18%;" (tap)="wajid()" (press) = "wajidlong5()">
<div class = "sections" id = "sec1" >
ﻞَ
</div><!--
--><div class = "sections" id = "sec2" >
ﻌَ
</div><!--
--><div class = "sections" id = "sec3" >
ﺟَ
</div>
</div>
【问题讨论】:
-
不是真的......你必须了解更多关于离子......它不是那么简单。
-
@Cristian 从那里我学会了实现这一点,我真的需要尽快做到这一点!帮帮我伙计
-
这里:ionicframework.com/docs/native,寻找文件传输,在那里你也可以检查文件是否已经存在
-
@Cristian 我需要从 Firebase 存储下载音频,然后检查它是否已经从资产播放,否则它将下载该音频并将其放置在资产文件夹中,然后从资产播放。请帮助:)
-
不能直接放入assets。检查 FILETRANSFER 离子插件