AudioPlayer icon indicating copy to clipboard operation
AudioPlayer copied to clipboard

percentageRead is always zero for streaming audios

Open ahsanaasim opened this issue 5 years ago • 0 comments

In my code, delegate method always returns percentageRead to be 0. For local files it works perfectly. But when streaming i am facing the issue... One thing i noticed, didFindDuration is not getting called.

This is my code

//
//  SharedPlayer.swift
//  Quran Touch
//
//  Created by Ahsan Aasim on 29/4/19.
//  Copyright © 2019 Ahsan Aasim. All rights reserved.
//

import Foundation
import KDEAudioPlayer

class SharedPlayer {
    static var shared = SharedPlayer()
    let player = AudioPlayer()
    var duration: TimeInterval = 0
    
    init() {
        player.delegate = self
    }
    
}

// MARK: - Audio Player Delegates
extension SharedPlayer: AudioPlayerDelegate {
    func audioPlayer(_ audioPlayer: AudioPlayer, didChangeStateFrom from: AudioPlayerState, to state: AudioPlayerState) {
        switch state {
        case .playing:
            if let current = audioPlayer.currentItem?.trackNumber {
            }
        case .paused:
            print("paused")
        case .stopped:
            print("stopped")
            if !audioPlayer.hasNext {
            }
        default:
            print("default \(state.self)")
        }
    }
    
    func audioPlayer(_ audioPlayer: AudioPlayer, didFindDuration duration: TimeInterval, for item: AudioItem) {
        //        print(duration)
        self.duration = duration
    }
    
    func audioPlayer(_ audioPlayer: AudioPlayer, didUpdateProgressionTo time: TimeInterval, percentageRead: Float) {
        print(percentageRead)
        NotificationCenter.default.post(name: .AudioPlayerProgressChanged, object: percentageRead/100)
        //        audioTrack.progress = percentageRead/100
    }
    
    func audioPlayer(_ audioPlayer: AudioPlayer, willStartPlaying item: AudioItem) {
        //        print(item.title)
        
    }
    
}

Output

Screenshot 2019-04-29 at 7 51 58 PM

for some audios, i am getting this on console. I have the domain added in exception domains

2019-04-29 19:52:00.598581+0600 Quran Touch[15929:219293] [AudioHAL_Client] AudioHardware.cpp:1210:AudioObjectRemovePropertyListener:  AudioObjectRemovePropertyListener: no object with given ID 0
2019-04-29 19:52:00.598772+0600 Quran Touch[15929:219293] [AudioHAL_Client] AudioHardware.cpp:1210:AudioObjectRemovePropertyListener:  AudioObjectRemovePropertyListener: no object with given ID 0
2019-04-29 19:52:00.598894+0600 Quran Touch[15929:219293] [AudioHAL_Client] AudioHardware.cpp:1210:AudioObjectRemovePropertyListener:  AudioObjectRemovePropertyListener: no object with given ID 0
2019-04-29 19:52:01.102890+0600 Quran Touch[15929:219304] Task <131734F5-C3B7-4810-BD61-76DB20E5ADD6>.<1> load failed with error Error Domain=NSURLErrorDomain Code=-999 "cancelled" UserInfo={NSErrorFailingURLStringKey=http://cdn.alquran.cloud/media/audio/ayah/ar.alafasy/31, NSErrorFailingURLKey=http://cdn.alquran.cloud/media/audio/ayah/ar.alafasy/31, _NSURLErrorRelatedURLSessionTaskErrorKey=(
    "LocalDataTask <131734F5-C3B7-4810-BD61-76DB20E5ADD6>.<1>"
), _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <131734F5-C3B7-4810-BD61-76DB20E5ADD6>.<1>, NSLocalizedDescription=cancelled} [-999]
2019-04-29 19:52:01.104468+0600 Quran Touch[15929:218749] [AudioHAL_Client] AudioHardware.cpp:1210:AudioObjectRemovePropertyListener:  AudioObjectRemovePropertyListener: no object with given ID 0
2019-04-29 19:52:01.104700+0600 Quran Touch[15929:218749] [AudioHAL_Client] AudioHardware.cpp:1210:AudioObjectRemovePropertyListener:  AudioObjectRemovePropertyListener: no object with given ID 0
2019-04-29 19:52:01.104807+0600 Quran Touch[15929:218749] [AudioHAL_Client] AudioHardware.cpp:1210:AudioObjectRemovePropertyListener:  AudioObjectRemovePropertyListener: no object with given ID 0
2019-04-29 19:52:01.105070+0600 Quran Touch[15929:218749] [AudioHAL_Client] AudioHardware.cpp:1210:AudioObjectRemovePropertyListener:  AudioObjectRemovePropertyListener: no object with given ID 0
2019-04-29 19:52:01.105236+0600 Quran Touch[15929:218749] [AudioHAL_Client] AudioHardware.cpp:1210:AudioObjectRemovePropertyListener:  AudioObjectRemovePropertyListener: no object with given ID 0
2019-04-29 19:52:01.105388+0600 Quran Touch[15929:218749] [AudioHAL_Client] AudioHardware.cpp:1210:AudioObjectRemovePropertyListener:  AudioObjectRemovePropertyListener: no object with given ID 0
2019-04-29 19:52:01.111862+0600 Quran Touch[15929:218749] Task <131734F5-C3B7-4810-BD61-76DB20E5ADD6>.<1> finished with error - code: -999
2019-04-29 19:52:01.112315+0600 Quran Touch[15929:218430] TIC Read Status [42:0x0]: 1:57

ahsanaasim avatar Apr 29 '19 13:04 ahsanaasim