0

I'm running a simple AVPlayer in my app to play videos. When the play method is called the video is extraordinarily slow. The first frame will load, then the video will stop, then play for a second, then stop again for an indefinite period. Once the video is fully downloaded then the app has no trouble playing the video. If I run the app on WiFi everything works great. It's when I run on 3G that everything hits the crapper.

Videos are only several seconds long and average out at 2mbs in size. I'm using Apple's Network Link Conditioner to simulate a 3G connection.

Here's the code I'm using thus far.

override func viewDidLoad() {
    super.viewDidLoad()

    playVideo()
}

func playVideo() {    
        let player = AVPlayer(URL: NSURL(string: "https://v.cdn.vine.co/r/videos/F55E4599581253064746484789248_4e75fe014aa.0.1.6509938863005525920.mp4")!)

        player.volume = 0.5

        player.actionAtItemEnd = AVPlayerActionAtItemEnd.None

        let playerController = AVPlayerViewController()

        playerController.player = player

        playerController.showsPlaybackControls = false

        self.addChildViewController(playerController)

        self.view.addSubview(playerController.view)

        playerController.view.frame = self.view.frame

        player.play()
    }
}

I also created a github repo with an example.

What's wrong and is there any way I can fix this to improve download speed?

thank_you
  • 11,001
  • 19
  • 101
  • 185
  • I'm completely new to this, so it might not help, but I've never see the use of `def` to define a function in swift; shouldn't it be `func playVideo() {...}`? Other thing: shouldn't it be `playerController.player = newPlayer`? – RoberRM Sep 17 '15 at 17:00
  • Ugh sorry. Copying mistakes from moving code over. Now fixed. Thanks for noticing that. The question still holds true. – thank_you Sep 17 '15 at 17:10
  • And shouldn't you change `playerController.player = player` to `playerController.player = newPlayer`? The way I see it, if you use `playerController.player = player` there then the previous lines where you set the volume and the end action will not work... Will they? Other than these little things, I'm afraid I cannot help you more. Sorry. ... ... Oh! I just saw your edit, sorry. – RoberRM Sep 17 '15 at 17:17
  • By the way, I guess the obvious answer is too obvious and won't be of use either, but I'll ask anyway because I cannot see anything else wrong in your code: do you have good 3G coverage where you are, right? Does that same video load fast enough in Safari for your phone? – RoberRM Sep 17 '15 at 17:24
  • I could and you are right but it is irrelevant to my question. The 3G coverage I'm implementing is through the Hardware Tools provided by Apple when testing various network speeds on your iOS devices. – thank_you Sep 17 '15 at 17:38
  • Are you sure the two numbers you're seeing are both in _kilobits_? 8*93 = 744, which is a lot closer to the 780 you were expecting. So, are you sure the "93" figure is in kilobits (kb) and not kilobytes (KB)? – Adam S Sep 17 '15 at 18:01
  • I just fired up Xcode and had a look - the network monitor reads `KB`, and the Developer Options > Network Link Conditioner entry reads `Kbps` - so the two figures are in different units, and _do_ seem to match up. I grabbed your sample repo and can only get it to load the first second or so with the 3G setting turned on (on my iPad Mini Wifi), but from what you described... the numbers sound correct. – Adam S Sep 17 '15 at 18:13
  • Hmm. So this is expected? When I use other apps that use short videos like Snapchat with my 3G settings turned on everything is smooth on their app. Same goes for youtube. However, if I use my app, the app is gruelingly slow. – thank_you Sep 17 '15 at 18:30

0 Answers0