Пример #1
0
        internal PlaybackData GetPlaybackData(string id, bool create = true)
        {
            lock (CurrentData) {
                PlaybackData data;
                if (!CurrentData.TryGetValue(id, out data) && create)
                {
                    CurrentData [id] = data = new PlaybackData {
                        SongId = id,
                    }
                }
                ;
                return(data);
            }
        }

        Dictionary <Tuple <string, bool>, Task <Tuple <bool, PlaybackData> > > prepareTasks = new Dictionary <Tuple <string, bool>, Task <Tuple <bool, PlaybackData> > > ();
Пример #2
0
        internal PlaybackData GetPlaybackData(string id, bool create = true)
        {
            lock (CurrentData)
            {
                PlaybackData data;
                if (!CurrentData.TryGetValue(id, out data) && create)
                {
                    CurrentData[id] = data = new PlaybackData
                    {
                        SongId = id,
                    }
                }
                ;
                return(data);
            }
        }

        void finishedPlaying(Song song)
        {
            ScrobbleManager.Shared.PlaybackEnded(new PlaybackEndedEvent(song)
            {
                TrackId  = Settings.CurrentTrackId,
                Context  = Settings.CurrentPlaybackContext,
                Position = this.CurrentTime,
                Reason   = ScrobbleManager.PlaybackEndedReason.PlaybackEnded,
            });
            CleanupSong(song);
            State = PlaybackState.Stopped;
#pragma warning disable 4014
            PlaybackManager.Shared.NextTrack();
#pragma warning restore 4014
        }

        void TryPlayAgain(string songId)
        {
            var song = Database.Main.GetObject <Song, TempSong>(songId);

            CleanupSong(song);
            PlaySong(song, isVideo);
        }
Пример #3
0
        async void ProcessesRequest(AVAssetResourceLoader resourceLoader,
                                    AVAssetResourceLoadingRequest loadingRequest, PlaybackData data)
        {
            if (data == null)
            {
                loadingRequest.FinishLoading();
                return;
            }
            try
            {
                var currentDownloadHelper = data.DownloadHelper;
                var content = loadingRequest.ContentInformationRequest;
                if (content != null)
                {
                    content.ByteRangeAccessSupported = true;

                    if (string.IsNullOrWhiteSpace(currentDownloadHelper.MimeType))
                    {
                        var success = await currentDownloadHelper.WaitForMimeType();
                    }
                    content.ContentType   = currentDownloadHelper.MimeType;
                    content.ContentLength = currentDownloadHelper.TotalLength;
                }

                var dataRequest = loadingRequest.DataRequest;

                Console.WriteLine(
                    $"Data Request: {dataRequest.RequestedOffset} - {dataRequest.RequestedLength} : {dataRequest.CurrentOffset} - {currentDownloadHelper.TotalLength}");
                var  allData   = Device.IsIos9 && dataRequest.RequestsAllDataToEndOfResource;
                long exspected = allData ? Math.Max(dataRequest.RequestedLength, currentDownloadHelper.TotalLength) : dataRequest.RequestedLength;
                int  sent      = 0;
                var  bufer     = new byte[exspected];
                lock (currentDownloadHelper)
                {
                    while (sent < exspected)
                    {
                        if (data.CancelTokenSource.IsCancellationRequested)
                        {
                            loadingRequest.FinishLoading();
                            return;
                        }
                        var startOffset = dataRequest.CurrentOffset != 0 ? dataRequest.CurrentOffset : dataRequest.RequestedOffset;
                        var remaining   = exspected - sent;
                        currentDownloadHelper.Position = startOffset;
                        if (loadingRequest.IsCancelled)
                        {
                            break;
                        }
                        var read       = currentDownloadHelper.Read(bufer, 0, (int)remaining);
                        var sendBuffer = bufer.Take(read).ToArray();
                        dataRequest.Respond(NSData.FromArray(sendBuffer));
                        sent += read;
                        if (sent + startOffset >= currentDownloadHelper.TotalLength)
                        {
                            break;
                        }
                    }
                }
                if (!loadingRequest.IsCancelled)
                {
                    loadingRequest.FinishLoading();
                    if (NativeAudioPlayer.Shared.State == PlaybackState.Buffering || NativeAudioPlayer.Shared.State == PlaybackState.Playing)
                    {
                        NativeAudioPlayer.Shared.player.CurrentPlayer.Play();
                    }
                }
            }
            catch (Exception ex)
            {
                loadingRequest.FinishLoadingWithError(new NSError((NSString)ex.Message, 0));
                TryPlayAgain(data.SongId);
                Console.WriteLine("***************** ERROR ******************");
                Console.WriteLine("Error in Resouce Loader. Trying Again\r\n {0}", ex);
                Console.WriteLine("*******************************************");
            }
        }