2016-11-12 67 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你可以用任何文件替換圖像文件

相關問題