2

Im creating an application when i want to stream mp3 files. Im using AvPlayer class. When i create avplayer instance i put file uri in constructor like:

_player = AVPlayer.FromUrl(NSUrl.FromString("Url");
_player.Play();

It is an c# code but i think its very similar to swift. When i call play method the mp3 file is downloading instead of streaming. I try to play long mp3 file (something about 50 minutes) and loading did takes to much time. When loading ends, mp3 play, but when i turn internet connection off and seek to the end, playback continue.

How can i tell to avplayer that he have to streaming. I found a SO question Why AVPlayer downloading first instead live streaming? but there is no solution.

Android MediaPlayer stream this mp3 without any problems.

puko
  • 2,819
  • 4
  • 18
  • 27

1 Answers1

2

Start from iOS 10, set the AutomaticallyWaitsToMinimizeStalling to false or custom the time to delay:

public override void ViewDidLoad ()
{
    base.ViewDidLoad ();
    // Perform any additional setup after loading the view, typically from a nib.

    AVPlayerItem item = new AVPlayerItem(new NSUrl("https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3"));
    AVPlayer _player = new AVPlayer(item);
    _player.AutomaticallyWaitsToMinimizeStalling = false;
    _player.Play();
}

Refer: avplayer-stops-playing-video-after-buffering

nevermore
  • 15,432
  • 1
  • 12
  • 30