2016-11-12 102 views
0

我新的火力点,我怎样才能改变这种从本地获取文件,以火力存储如何更改代码从火力存储,而不是本地下载文件

override func viewDidLoad() { 
     super.viewDidLoad() 

     trackLbl.text = "Track \(trackID + 1)" 
     // 1 
     let path: String! = Bundle.main.resourcePath?.appending("/\(trackID!).mp3") 
     let mp3URL = NSURL(fileURLWithPath: path) 
     do 
     { 
      // 2 
      audioPlayer = try AVAudioPlayer(contentsOf: mp3URL as URL) 
      audioPlayer.play() 
      // 3 
      Timer.scheduledTimer(timeInterval: 1.0, target: self, selector: #selector(updateAudioProgressView), userInfo: nil, repeats: true) 
      progressView.setProgress(Float(audioPlayer.currentTime/audioPlayer.duration), animated: false) 
     } 
     catch 
     { 
      print("An error occurred while trying to extract audio file") 
     } 

      } 
+0

从这里开始:https://firebase.google.com/docs/storage/ios/start –

回答

0

希望你已经创建火力地堡项目,并上载文件存储,你正在寻找加载 请按照下面的指导

安装荚

# Pull in Firebase Storage features 
pod 'FirebaseUI/Storage', '~> 0.6' 

// Create a reference with an initial file path and name 
let pathReference = storage.reference("images/stars.jpg") 

// Create a reference from a Google Cloud Storage URI 
let gsReference = storage.referenceForURL('gs://bucket/images/stars.jpg') 

// Create a reference from an HTTPS URL 
// Note that in the URL, characters are URL escaped! 
let httpsReference = storage.referenceForURL('https://firebasestorage.googleapis.com/b/bucket/o/images%20stars.jpg') 

现在你有三种方式在存储器中取出

下载

// Create a reference to the file you want to download 
let islandRef = storageRef.child("images/island.jpg") 

// Download in memory with a maximum allowed size of 1MB (1 * 1024 * 1024 bytes) 
islandRef.dataWithMaxSize(1 * 1024 * 1024) { (data, error) -> Void in 
    if (error != nil) { 
    // Uh-oh, an error occurred! 
    } else { 
    // Data for "images/island.jpg" is returned 
    // ... let islandImage: UIImage! = UIImage(data: data!) 
    } 
} 

下载到本地文件

// Create a reference to the file you want to download 
let islandRef = storageRef.child("images/island.jpg") 

// Create local filesystem URL 
let localURL: NSURL! = NSURL(string: "file:///local/images/island.jpg") 

// Download to the local filesystem 
let downloadTask = islandRef.writeToFile(localURL) { (URL, error) -> Void in 
    if (error != nil) { 
    // Uh-oh, an error occurred! 
    } else { 
    // Local file URL for "images/island.jpg" is returned 
    } 
} 

生成一个下载网址

// Create a reference to the file you want to download 
let starsRef = storageRef.child("images/stars.jpg") 

// Fetch the download URL 
starsRef.downloadURLWithCompletion { (URL, error) -> Void in 
    if (error != nil) { 
    // Handle any errors 
    } else { 
    // Get the download URL for 'images/stars.jpg' 
    } 
} 

脱颖而出更多信息请访问[火力地堡d] [1]

[1]:https://firebase.google.com/docs/storage/ios/download-files你可以用任何文件替换图像文件

相关问题