Exemplo n.º 1
0
        /// <summary>
        /// Implements the logic to get the previous AudioTrack instance.
        /// </summary>
        /// <remarks>
        /// The AudioTrack URI determines the source, which can be:
        /// (a) Isolated-storage file (Relative URI, represents path in the isolated storage)
        /// (b) HTTP URL (absolute URI)
        /// (c) MediaStreamSource (null)
        /// </remarks>
        /// <returns>an instance of AudioTrack, or null if previous track is not allowed</returns>
        private AudioTrack GetPreviousTrack(AudioTrack audioTrack, Func <List <GuidToTrackMapping>, AudioTrack, GuidToTrackMapping> definePreviousTrackPredicate)
        {
            if (definePreviousTrackPredicate == null)
            {
                throw new ArgumentNullException("definePreviousTrackPredicate");
            }


            AudioTrack track = null;

            if (audioTrack != null && !string.IsNullOrWhiteSpace(audioTrack.Tag))
            {
                GuidToTrackMapping guidToTrackMapping = definePreviousTrackPredicate(_tracksToGuidMapping, audioTrack);

                if (guidToTrackMapping != null)
                {
                    SynoTrack nextTrack = guidToTrackMapping.Track;

                    // is there a fix we can apply ?
                    if (_asciiUriFixes.Any(fix => fix.Res == nextTrack.Res))
                    {
                        track = _audioTrackFactory.Create(nextTrack, guidToTrackMapping.Guid, _playqueueInformation.Host, _playqueueInformation.Port, _playqueueInformation.Token, _asciiUriFixes.Single(fix => fix.Res == nextTrack.Res).Url);
                    }
                    else
                    {
                        track = _audioTrackFactory.Create(nextTrack, guidToTrackMapping.Guid, _playqueueInformation.Host, _playqueueInformation.Port, _playqueueInformation.Token);
                    }
                    // new AudioTrack(new Uri(nextTrack.Res), nextTrack.Title, nextTrack.Artist, nextTrack.Album, new Uri(nextTrack.AlbumArtUrl), guidToTrackMapping.Guid.ToString(), EnabledPlayerControls.All);
                    // new AudioTrack(new Uri(nextTrack.Res), nextTrack.Title, nextTrack.Artist, nextTrack.Album, new Uri(nextTrack.AlbumArtUrl), guidToTrackMapping.Guid.ToString(), EnabledPlayerControls.All);
                }
            }

            return(track);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Implements the logic to get the next AudioTrack instance.
        /// In a playlist, the source can be from a file, a web request, etc.
        /// </summary>
        /// <param name="audioTrack"></param>
        /// <remarks>
        /// The AudioTrack URI determines the source, which can be:
        /// (a) Isolated-storage file (Relative URI, represents path in the isolated storage)
        /// (b) HTTP URL (absolute URI)
        /// (c) MediaStreamSource (null)
        /// </remarks>
        /// <returns>an instance of AudioTrack, or null if the playback is completed</returns>
        private AudioTrack GetNextTrack(AudioTrack audioTrack, Func <List <GuidToTrackMapping>, AudioTrack, GuidToTrackMapping> defineNextTrackPredicate)
        {
            if (defineNextTrackPredicate == null)
            {
                throw new ArgumentNullException("defineNextTrackPredicate");
            }

            if (audioTrack != null && !string.IsNullOrWhiteSpace(audioTrack.Tag))
            {
                GuidToTrackMapping guidToTrackMapping = defineNextTrackPredicate(_tracksToGuidMapping, audioTrack);

                if (guidToTrackMapping != null)
                {
                    AudioTrack track;
                    SynoTrack  nextTrack = guidToTrackMapping.Track;

                    // is there a fix we can apply ?
                    if (_asciiUriFixes.Any(fix => fix.Res == nextTrack.Res))
                    {
                        AsciiUriFix asciiUriFix = this._asciiUriFixes.Single(fix => fix.Res == nextTrack.Res);
                        if (asciiUriFix.Url == null)
                        {
                            throw new NotSupportedException("We knew this day will come eventually : we just imagined that this would not happen anytime soon, so being agile, we didn't implement it yet : we need to support the scenario where a track is started from the phone's UI instead of the app's. (AudioPlayer.cs::GetNextTrack()");
                        }
                        track = _audioTrackFactory.Create(nextTrack, guidToTrackMapping.Guid, _playqueueInformation.Host, _playqueueInformation.Port, _playqueueInformation.Token, asciiUriFix.Url);
                    }
                    else
                    {
                        track = _audioTrackFactory.Create(nextTrack, guidToTrackMapping.Guid, _playqueueInformation.Host, _playqueueInformation.Port, _playqueueInformation.Token);
                    }
                    // new AudioTrack(new Uri(nextTrack.Res), nextTrack.Title, nextTrack.Artist, nextTrack.Album, new Uri(nextTrack.AlbumArtUrl), guidToTrackMapping.Guid.ToString(), EnabledPlayerControls.All);
                    // new AudioTrack(new Uri(nextTrack.Res), nextTrack.Title, nextTrack.Artist, nextTrack.Album, new Uri(nextTrack.AlbumArtUrl), guidToTrackMapping.Guid.ToString(), EnabledPlayerControls.All);

                    return(track);
                }
            }


            // specify the track

            return(null);
        }
Exemplo n.º 3
0
        public void RemoveTracksFromQueue(IEnumerable <Guid> tracksToRemove)
        {
            // If not using an array, an Invalid Operation Exception will be thrown : something about Movenext, maybe the enumerator is not correctly implemented.
            var trackToRemoveArray       = tracksToRemove.ToArray();
            PlayqueueChangedEventArgs ea = new PlayqueueChangedEventArgs();
            var guidToTrackMappings      = new GuidToTrackMapping[trackToRemoveArray.Length];
            int guidToTrackMappingIndex  = 0;

            foreach (var guid in trackToRemoveArray)
            {
                var guidToTrackMapping = _tracksToGuidMapping.Single(o => o.Guid == guid);


                _tracksToGuidMapping.Remove(guidToTrackMapping);

                guidToTrackMappings[guidToTrackMappingIndex] = guidToTrackMapping;
                guidToTrackMappingIndex++;
            }
            ea.RemovedItems = guidToTrackMappings;
            this.OnTracksInQueueChanged(ea);
        }