neekeetab / CachingPlayerItem

Play and cache media content simultaneously on your iOS device
MIT License
520 stars 89 forks source link

Update CachingPlayerItem.swift: Swift3 compatibility #4

Closed yeralin closed 6 years ago

yeralin commented 7 years ago

There is a problem tho. Nothing happens after i call .play()

    func playSong(song: DownloadSongEntity) {
        let songUrl = song.songUrl!
        let playerItem = CachingPlayerItem(url: songUrl)
        playerItem.delegate = self
        player = AVPlayer(playerItem: playerItem)
    }

    func playerItemReadyToPlay(playerItem: CachingPlayerItem) {
        print("Started playing")
        player.play()
    }

    func playerItemDidStopPlayback(playerItem: CachingPlayerItem) {
        print("Not enough data for playback. Probably because of the poor network. Wait a bit and try to play later.")
    }

    func playerItem(playerItem: CachingPlayerItem, didFinishDownloadingData data: NSData) {
        print("File is downloaded and ready for storing")
    }

    func playerItem(playerItem: CachingPlayerItem, didDownloadBytesSoFar bytesDownloaded: Int, outOf bytesExpected: Int) {
        print("Loaded so far: \(bytesDownloaded) out of \(bytesExpected)")
    }

Logs:

2017-07-01 00:05:32.673 MusicPlayer[49354:39064416] *** -[AVAssetResourceLoadingRequest finishLoading] was sent to an instance of AVAssetResourceLoadingRequest that was already finished. Ignoring.
Loaded so far: 7746 out of -1
Loaded so far: 1050076 out of -1
...
Started playing
...
Loaded so far: 3409965 out of -1
File is downloaded and ready for storing
yeralin commented 7 years ago

@neekeetab

yeralin commented 7 years ago

Разобрался я с этой хренью. Что у тебя там за "whatever" scheme ? Зачем оно вообще?

Как играть и качать одновременно? Я сейчас делаю:

func playerItemReadyToPlay(playerItem: CachingPlayerItem) {
        print("Started playing")
        player.play()
        playerItem.download()
    }

Но мне кажется оно дважды выкачивает файл :/

yeralin commented 6 years ago

Ooo now I got it: https://stackoverflow.com/questions/26649865/avassetresourceloaderdelegate-methods-not-working-on-device