Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NSURLConnection Error Code 1002 #18

Open
mnearents opened this issue Dec 1, 2018 · 13 comments
Open

NSURLConnection Error Code 1002 #18

mnearents opened this issue Dec 1, 2018 · 13 comments

Comments

@mnearents
Copy link

mnearents commented Dec 1, 2018

Hi, I am trying to use this with Firebase Storage. I have audio files stored there with URLs that look like this:

https://firebasestorage.googleapis.com/v0/b/audiomeshchat.appspot.com/o/projects%2H0wy4AwppfUSozaxeAMNGbA8Vyum1%2F0B7D5C4F-F65B-495C-A06E-35C236B5B5FC.m4a?alt=media&token=a5f7fcb3-0541-453e-8a47-55563518bbef6

My app works great with the following code:

let url = URL(string: (project?.url)!)!
let playerItem = AVPlayerItem(url: url)
player = AVPlayer(playerItem: playerItem)
player.automaticallyWaitsToMinimizeStalling = false
player.play()

But when I simply switch it to use CachingPlayerItem, the audio won't play and I get NSURLConnection error code 1002.

What's weird is the file is successfully downloaded and cached. But the audio player won't play. Is it possible to make this work with Firebase storage URLs? My security rules are set up such that without the token, files can't be accessed.

@neekeetab
Copy link
Owner

neekeetab commented Jan 2, 2019

Sorry for late response. Is this issue still a case? FYI, the link is broken.

@mnearents
Copy link
Author

Yeah, I sanitized the link, not sure if it was necessary, but yeah, it won’t work. And I haven’t tried it since. I assume it’s still a problem but I can check.

@neekeetab
Copy link
Owner

From your code I can see that you initialize ‘playerItem’ with just a url. And your url doesn’t contain a file extension. Thus, CachingPlayerItem can’t refer the type of the file. Try using another initializer that takes custom file extension along with url.

@mnearents
Copy link
Author

I tried that too, and it didn't work. The URL actually does contain a file extension. The problem is the token comes after the URL as an option in the URL string:

Here's the first part of the URL:
https://firebasestorage.googleapis.com/v0/b/audiomeshchat.appspot.com/o/projects%2H0wy4AwppfUSozaxeAMNGbA8Vyum1%2F0B7D5C4F-F65B-495C-A06E-35C236B5B5FC.m4a

And here are the query components, including the token:
?alt=media&token=a5f7fcb3-0541-453e-8a47-55563518bbef6

The file can't be accessed without the query components because of security rules.

@neekeetab
Copy link
Owner

Yeah, missed that part. If you provide a valid url I can take a look.

@neekeetab
Copy link
Owner

neekeetab commented Jan 3, 2019

Works fine for me. Here's the code:

let url = URL(string: "https://firebasestorage.googleapis.com/v0/b/foodapp-600e4.appspot.com/o/projects%2F2eoifj02gpwodsjg02ssd%2F02C3E19E-B3F5-4325-80D0-CF89F6B486DD.m4a?alt=media&token=b35bfd0a-663b-4584-9cf2-1e7d69fddcd3")!
let playerItem = CachingPlayerItem(url: url)
player = AVPlayer(playerItem: playerItem)
player.automaticallyWaitsToMinimizeStalling = false
player.play()

@neekeetab
Copy link
Owner

Also I've noticed that the file you provided starts playing only when fully downloaded as opposed to, say, https://github.com/robovm/apple-ios-samples/blob/master/avTouch/sample.m4a?raw=true. You might want to take a look at this issue #12.

@artur-zaremba
Copy link

I have the same issue when I try to access currentItem.asset right after play started.
Thats because audioPlayer?.currentItem?.duration is zero at start so I tried to get duration by calling this
let duration = audioPlayer?.currentItem?.asset.duration.seconds

Is there other way to do that?

@neekeetab
Copy link
Owner

Are you experiencing the same crash when you try to access an asset? If it's just about getting the duration, then take into account that a file should contain certain metadata in order for you to know the duration before the file is fully loaded. Please take a look at #12.
@artur-zaremba

@artur-zaremba
Copy link

artur-zaremba commented Mar 18, 2019

Yes, I am. The issue is raised when I access asset immediately after start playing. I avoid the issue by checking if currentItem.status == .readyToPlay then I access the asset.
Also I experienced app freeze before the error code 1002. It seems that I accessed it when initial chunk of asset was loading.

@murad1981
Copy link

murad1981 commented Apr 25, 2019

did anybody manage to solve 1002 error code ? I'm facing the same issue with the url: https://www.sample-videos.com/audio/mp3/crowd-cheering.mp3

@jsmith
Copy link

jsmith commented Oct 11, 2020

I am also having this issue unfortunately! It only seems to happen like 15% of the time and not always the same song. Sound works initially but it stops after the 1002 error happens for the first time. I'm going to keep debugging!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants