无法在IOS设备上定位和回放以前的记录

时间:2018-07-16 12:44:33

标签: ios swift amazon-dynamodb avaudioplayer

我正在尝试在同一设备上播放以前(在IOS上)录制的音频文件。我将数据存储在Amazon的Mobile-hub DynamoDB上,但是以某种方式尝试播放相同的文件时找不到它。

我在控制台上添加了一些打印件,以试图弄清发生了什么。我已经看了几天了。...

我还使用info.plist设置激活了此应用的文件共享。在iTunes中,我可以看到文件,将其保存并在Mac上播放。

这是我的代码:

import Foundation

import UIKit
import AVFoundation
import AWSCore
import AWSMobileClient
import AWSDynamoDB

class ListenViewController: UIViewController, UITextFieldDelegate {

    var storyUserId: String = "Noname"
    var storyDateTime: String = "Today"
    var player: AVAudioPlayer?

    override func viewDidLoad() {
        super.viewDidLoad()

        print("[NARRATOR DEBUG] Entering the listenviewcontoller", storyUserId, storyDateTime)
        //first create expression
        let queryExpression = AWSDynamoDBQueryExpression()
        storyDateTime = "Today"
        queryExpression.keyConditionExpression = "#attribute1 = :value1 AND #attribute2 = :value2"
        queryExpression.expressionAttributeNames = ["#attribute1": "storyUserId","#attribute2": "storyDateTime"]
        queryExpression.expressionAttributeValues = [":value1": "roger", ":value2": storyDateTime]

        let dynamoDbObjectMapper = AWSDynamoDBObjectMapper.default()

        dynamoDbObjectMapper.query(Stories.self, expression: queryExpression)
        { (output: AWSDynamoDBPaginatedOutput?, error: Error?) in
            print ("[NARRATOR DEBUG ", error.debugDescription)
            print ("[NARRATOR DEBUG ", output!.items)
            print ("[NARRATOR DEBUG] The request failed. Error: \(String(describing: error))")
            if error != nil {
                print("[NARRATOR DEBUG] The request failed. Error: \(String(describing: error))")
            }
            if output != nil {
                print(output!.items)
                for stories in output!.items {
                    let story = stories as? Stories
                    print("[NARRATOR DEBUG] Pin read \(story!._storyUserId!)")
                    print("[NARRATOR DEBUG] Pin read \(story!._storyName!)")
                    print("[NARRATOR DEBUG] Pin read \(story!._storyDateTime!)")
                    print("[NARRATOR DEBUG] Pin read \(story!._storyAudioFilename!)")
                    print("[NARRATOR DEBUG] Pin read \(story!._storyLongitude!)")
                    print("[NARRATOR DEBUG] Pin read \(story!._storyLatitude!)")

                    let audioFileURL = story!._storyAudioFilename
                    let url = URL(string: audioFileURL!)
                    print ("[NARATOR DEBUG] Playing audiofile URL: \(url!)")

                    let fileManager = FileManager.default
                    if fileManager.fileExists(atPath: audioFileURL!) {
                        print("FILE AVAILABLE", audioFileURL!)
                    } else {
                        print("FILE NOT AVAILABLE", audioFileURL!, fileManager.debugDescription, url!)
                    }

                    do {
                        try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback)
                        try AVAudioSession.sharedInstance().setActive(true)
                        self.player = try AVAudioPlayer(contentsOf: url!, fileTypeHint: nil)
                        self.player?.play()
                    } catch let error {
                        print(error.localizedDescription)
                    }
                }
            } else {
                print("[NARRATOR DEBUG] No data read from the table")
            }
        }
        print("[NARRATOR DEBUG] Leaving the listenviewcontoller")
    }
}

控制台上的输出如下:

[NARRATOR DEBUG] The request failed. Error: nil
[<narrator.Stories: 0x112eea360> {
    "_storyAltitude" = "<null>";
    "_storyAudioFilename" = "file:///var/mobile/Containers/Data/Application/B7258F8D-D389-48B6-8ACC-0D44C2717A4F/Documents/yGe12W2xi9qD.m4a";
    "_storyDateTime" = Today;
    "_storyLatitude" = 0;
    "_storyLongitude" = 0;
    "_storyName" = qWbHohvq;
    "_storyUserId" = roger;
    "_storyZoom" = "<null>";
}]
[NARRATOR DEBUG] Pin read roger
[NARRATOR DEBUG] Pin read qWbHohvq
[NARRATOR DEBUG] Pin read Today
[NARRATOR DEBUG] Pin read file:///var/mobile/Containers/Data/Application/B7258F8D-D389-48B6-8ACC-0D44C2717A4F/Documents/yGe12W2xi9qD.m4a
[NARRATOR DEBUG] Pin read 0
[NARRATOR DEBUG] Pin read 0
[NARATOR DEBUG] Playing audiofile URL: file:///var/mobile/Containers/Data/Application/B7258F8D-D389-48B6-8ACC-0D44C2717A4F/Documents/yGe12W2xi9qD.m4a
FILE NOT AVAILABLE file:///var/mobile/Containers/Data/Application/B7258F8D-D389-48B6-8ACC-0D44C2717A4F/Documents/yGe12W2xi9qD.m4a <NSFileManager: 0x10310a570> file:///var/mobile/Containers/Data/Application/B7258F8D-D389-48B6-8ACC-0D44C2717A4F/Documents/yGe12W2xi9qD.m4a
The operation couldn’t be completed. (OSStatus error 2003334207.)

非常感谢您的帮助。

0 个答案:

没有答案
相关问题