<commit_before>using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AVFoundation;
using CoreFoundation;
using CoreMedia;
using Foundation;
using Plugin.MediaManager.Abstractions;
using Plugin.MediaManager.Abstractions.Enums;
using Plugin.MediaManager.Abstractions.EventArguments;

namespace Plugin.MediaManager
{
    public class AudioPlayerImplementation : NSObject, IAudioPlayer
    {
        private readonly IVolumeManager _volumeManager;

        private readonly IVersionHelper _versionHelper;

        private IMediaFile _currentMediaFile;

        public static readonly NSString StatusObservationContext = new NSString("Status");

        public static readonly NSString RateObservationContext = new NSString("Rate");

        public static readonly NSString LoadedTimeRangesObservationContext = new NSString("TimeRanges");

        private AVPlayer _player;
        private MediaPlayerStatus _status;

        public Dictionary<string, string> RequestHeaders { get; set; }

        public AudioPlayerImplementation(IVolumeManager volumeManager)
        {
            _volumeManager = volumeManager;
            _versionHelper = new VersionHelper();

            _status = MediaPlayerStatus.Stopped;

            // Watch the buffering status. If it changes, we may have to resume because the playing stopped because of bad network-conditions.
            BufferingChanged += (sender, e) =>
            {
                // If the player is ready to play, it's paused and the status is still on PLAYING, go on!
                var isPlaying = Status == MediaPlayerStatus.Playing;
                if (CurrentItem.Status == AVPlayerItemStatus.ReadyToPlay && Rate == 0.0f && isPlaying)
                    Player.Play();
            };
        }

        private AVPlayer Player
        {
            get
            {
                if (_player == null)
                    InitializePlayer();
                
                return _player;
            }
        }

        private NSObject PeriodicTimeObserverObject;<commit_msg>Revert "Revert "Change to fix crash setting IOS volume before player is initialized""<commit_after>using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AVFoundation;
using CoreFoundation;
using CoreMedia;
using Foundation;
using Plugin.MediaManager.Abstractions;
using Plugin.MediaManager.Abstractions.Enums;
using Plugin.MediaManager.Abstractions.EventArguments;

namespace Plugin.MediaManager
{
    public class AudioPlayerImplementation : NSObject, IAudioPlayer
    {
        private readonly IVolumeManager _volumeManager;

        private readonly IVersionHelper _versionHelper;

        private IMediaFile _currentMediaFile;

        public static readonly NSString StatusObservationContext = new NSString("Status");

        public static readonly NSString RateObservationContext = new NSString("Rate");

        public static readonly NSString LoadedTimeRangesObservationContext = new NSString("TimeRanges");

        private AVPlayer _player;
        private MediaPlayerStatus _status;

        public Dictionary<string, string> RequestHeaders { get; set; }

        public AudioPlayerImplementation(IVolumeManager volumeManager)
        {
            _volumeManager = volumeManager;
            _versionHelper = new VersionHelper();

            _status = MediaPlayerStatus.Stopped;

            InitializePlayer();

            // Watch the buffering status. If it changes, we may have to resume because the playing stopped because of bad network-conditions.
            BufferingChanged += (sender, e) =>
            {
                // If the player is ready to play, it's paused and the status is still on PLAYING, go on!
                var isPlaying = Status == MediaPlayerStatus.Playing;
                if (CurrentItem.Status == AVPlayerItemStatus.ReadyToPlay && Rate == 0.0f && isPlaying)
                    Player.Play();
            };
        }

        private AVPlayer Player
        {
            get
            {
                if (_player == null)
                    InitializePlayer();
                
                return _player;
            }
        }

        private NSObject PeriodicTimeObserverObject;
{'fraction_non_alphanumeric': 0.06371317652432062, 'fraction_numerical': 0.0009134505594884677, 'mean_word_length': 2.4789515488482925, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3216332', 'n_tokens_mistral': 1055, 'n_tokens_neox': 989, 'n_words': 316}