Пример #1
0
        public void StreamTrack(Guid guidOfTrackToPlay)
        {
            _logService.Trace("Starting track streaming for track guid " + guidOfTrackToPlay);
            //// hack : Synology's webserver doesn't accept the + character as a space : it needs a %20, and it needs to have special characters such as '&' to be encoded with %20 as well, so an HtmlEncode is not an option, since even if a space would be encoded properly, an ampersand (&) would be translated into &
            //string url =
            //    string.Format(
            //        "http://{0}:{1}/audio/webUI/audio_stream.cgi/0.mp3?sid={2}&action=streaming&songpath={3}",
            //        _audioStationSession.Host,
            //        _audioStationSession.Port,
            //        _audioStationSession.Token.Split('=')[1],
            //        HttpUtility.UrlEncode(trackToPlay.Res).Replace("+", "%20"));
            SynoTrack  baseSynoTrack = _tracksToGuidMapping.Single(o => o.Guid == guidOfTrackToPlay).Track;
            AudioTrack audioTrack;

            if (_asciiUriFixes.Any(fix => fix.Res == baseSynoTrack.Res))
            {
                AsciiUriFix asciiUriFix = this._asciiUriFixes.Single(fix => fix.Res == baseSynoTrack.Res);
                asciiUriFix.CallbackWhenFixIsApplicable(fix =>
                {
                    audioTrack = _audioTrackFactory.Create(baseSynoTrack, guidOfTrackToPlay, _audioStationSession.Host, _audioStationSession.Port, _audioStationSession.Token, asciiUriFix.Url);
                    BackgroundAudioPlayer.Instance.Track = audioTrack;
                    BackgroundAudioPlayer.Instance.Play();
                });
            }
            else
            {
                audioTrack = _audioTrackFactory.Create(baseSynoTrack, guidOfTrackToPlay, _audioStationSession.Host, _audioStationSession.Port, _audioStationSession.Token);
                BackgroundAudioPlayer.Instance.Track = audioTrack;
                BackgroundAudioPlayer.Instance.Play();
            }
        }
Пример #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);
        }