/// <summary> /// Gets the remote file network stream. /// </summary> /// <param name="synoTrack">The track wor which to retrieve the stream.</param> /// <param name="callback">The method to call after the stream is open. The stream itself and its content length are passed as arguments.</param> /// <remarks>The caller is responsible for closing the stream after the call to DownloadFile returns</remarks> public void GetFileStream(SynoTrack synoTrack, Action <WebResponse, SynoTrack> callback) { if (synoTrack == null) { throw new ArgumentNullException("synoTrack"); } if (callback == null) { throw new ArgumentNullException("callback"); } var client = new WebClient(); var request = (HttpWebRequest)WebRequest.Create("http://www.toetapz.com/downloads/charge.mp3"); //Set request headers. request.Accept = "application/x-ms-application, image/jpeg, application/xaml+xml, image/gif, image/pjpeg, application/x-ms-xbap, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*"; //request.Headers.Set(HttpRequestHeader.AcceptLanguage, "en-US"); //request.UserAgent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; InfoPath.2; OfficeLiveConnector.1.5; OfficeLivePatch.1.3; Zune 4.7)"; //request.Headers.Set(HttpRequestHeader.AcceptEncoding, "gzip, deflate"); //request.Headers.Set(HttpRequestHeader.Cookie, @"__utma=11735858.713408819.1284879944.1294622128.1297023459.8; __utmz=11735858.1297023459.8.8.utmcsr=google|utmccn=(organic)|utmcmd=organic|utmctr=TiltEffect%20Toolkit; __qca=P0-1026483267-1284879945945"); request.BeginGetResponse(OnFileDownloadResponseReceived, new FileDownloadResponseReceivedUserState(request, callback, synoTrack)); }
public TrackViewModel(Guid guid, SynoTrack synoTrack, IPageSwitchingService pageSwitchingService, AlbumViewModelFactory albumViewModelFactory, IAudioStationSession session, IUrlParameterToObjectsPlateHeater urlParameterToObjectsPlateHeater, ITrackViewModelFactory trackViewModelFactory, INotificationService notificationService) { if (synoTrack == null) { throw new ArgumentNullException("synoTrack"); } if (session == null) { throw new ArgumentNullException("session"); } _trackViewModelFactory = trackViewModelFactory; _notificationService = notificationService; if (albumViewModelFactory == null) throw new ArgumentNullException("albumViewModelFactory"); Guid = guid; TrackInfo = synoTrack; NavigateToContainingAlbumCommand = new DelegateCommand(OnNavigateToContainingAlbum); this._session = session; this._urlParameterToObjectsPlateHeater = urlParameterToObjectsPlateHeater; _albumViewModelFactory = albumViewModelFactory; _albumViewModelFactory = albumViewModelFactory; _pageSwitchingService = pageSwitchingService; }
/// <summary> /// Gets the remote file network stream. /// </summary> /// <param name="synoTrack">The track wor which to retrieve the stream.</param> /// <param name="callback">The method to call after the stream is open. The HttpResponse is passed as argument</param> /// <remarks>The caller is responsible for closing the stream after the call to DownloadFile returns</remarks> public void GetFileStream(SynoTrack synoTrack, Action <WebResponse, SynoTrack> callback) { if (synoTrack == null) { throw new ArgumentNullException("synoTrack"); } if (callback == null) { throw new ArgumentNullException("callback"); } var client = new WebClient(); // 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 & var relativePathToAudioStreamService = this.versionDependentResourcesProvider.GetAudioStreamWebserviceRelativePath(this.DsmVersion); string url = string.Format("http://{0}:{1}{2}/0.mp3?action=streaming&songpath={3}", this.Host, this.Port, relativePathToAudioStreamService, HttpUtility.UrlEncode(synoTrack.Res).Replace("+", "%20").Replace("&", "%26")); var request = (HttpWebRequest)WebRequest.Create(url); request.CookieContainer = new CookieContainer(); request.CookieContainer.SetCookies(new Uri(url), this.Token); //Set request headers. request.Accept = "application/x-ms-application, image/jpeg, application/xaml+xml, image/gif, image/pjpeg, application/x-ms-xbap, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*"; //request.Headers.Set(HttpRequestHeader.AcceptLanguage, "en-US"); //request.UserAgent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; InfoPath.2; OfficeLiveConnector.1.5; OfficeLivePatch.1.3; Zune 4.7)"; //request.Headers.Set(HttpRequestHeader.AcceptEncoding, "gzip, deflate"); //request.Headers.Set(HttpRequestHeader.Cookie, @"__utma=11735858.713408819.1284879944.1294622128.1297023459.8; __utmz=11735858.1297023459.8.8.utmcsr=google|utmccn=(organic)|utmcmd=organic|utmctr=TiltEffect%20Toolkit; __qca=P0-1026483267-1284879945945"); request.AllowReadStreamBuffering = false; request.BeginGetResponse(OnFileDownloadResponseReceived, new FileDownloadResponseReceivedUserState(request, callback, synoTrack)); }
public AudioTrack Create(SynoTrack baseSynoTrack, Guid guid, string host, int port, string token, string urlOverride) { if (baseSynoTrack == null) { throw new ArgumentNullException("baseSynoTrack"); } if (host == null) { throw new ArgumentNullException("host"); } if (token == null) { throw new ArgumentNullException("token"); } if (urlOverride == null) { throw new ArgumentNullException("urlOverride"); } return new AudioTrack( new Uri(urlOverride), baseSynoTrack.Title, baseSynoTrack.Artist, baseSynoTrack.Album, new Uri(baseSynoTrack.AlbumArtUrl), guid.ToString(), EnabledPlayerControls.All); }
public AudioTrack Create(SynoTrack baseSynoTrack, Guid guid, string host, int port, string token) { if (baseSynoTrack == null) { throw new ArgumentNullException("baseSynoTrack"); } if (host == null) { throw new ArgumentNullException("host"); } if (token == null) { throw new ArgumentNullException("token"); } // 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 & var relativePathToAudioStreamService = this.versionDependentResourcesProvider.GetAudioStreamWebserviceRelativePath(DsmVersions.V4_0); string url = string.Format( "http://{0}:{1}{2}/0.mp3?sid={3}&action=streaming&songpath={4}", host, port, relativePathToAudioStreamService, token.Split('=')[1], HttpUtility.UrlEncode(baseSynoTrack.Res).Replace("+", "%20")); return Create(baseSynoTrack, guid,host, port, token, url); // ugly fix for backgroundAudioPlayer that does not support & > 7bits characters //if (baseSynoTrack.Res.Contains("&") || baseSynoTrack.Res.Any(o => o > 127)) //{ // // Use url-shortening service. // // http://t0.tv/api/shorten?u=<url> // WebClient webClient = new WebClient(); // string result = null; // var mre = new ManualResetEvent(false); // webClient.DownloadStringCompleted += (s, e) => // { // result = e.Result; // mre.Set(); // }; // webClient.DownloadStringAsync(new Uri("http://t0.tv/api/shorten?u=" + url )); // mre.WaitOne(); // JObject jo = JObject.Parse(result); // url = jo["short_url"].Value<string>(); //} }
/// <summary> /// Gets the remote file network stream. /// </summary> /// <param name="synoTrack">The track wor which to retrieve the stream.</param> /// <param name="callback">The method to call after the stream is open. The stream itself and its content length are passed as arguments.</param> /// <remarks>The caller is responsible for closing the stream after the call to DownloadFile returns</remarks> public void GetFileStream(SynoTrack synoTrack, Action<WebResponse, SynoTrack> callback) { if (synoTrack == null) { throw new ArgumentNullException("synoTrack"); } if (callback == null) { throw new ArgumentNullException("callback"); } var client = new WebClient(); var request = (HttpWebRequest)WebRequest.Create("http://www.toetapz.com/downloads/charge.mp3"); //Set request headers. request.Accept = "application/x-ms-application, image/jpeg, application/xaml+xml, image/gif, image/pjpeg, application/x-ms-xbap, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*"; //request.Headers.Set(HttpRequestHeader.AcceptLanguage, "en-US"); //request.UserAgent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; InfoPath.2; OfficeLiveConnector.1.5; OfficeLivePatch.1.3; Zune 4.7)"; //request.Headers.Set(HttpRequestHeader.AcceptEncoding, "gzip, deflate"); //request.Headers.Set(HttpRequestHeader.Cookie, @"__utma=11735858.713408819.1284879944.1294622128.1297023459.8; __utmz=11735858.1297023459.8.8.utmcsr=google|utmccn=(organic)|utmcmd=organic|utmctr=TiltEffect%20Toolkit; __qca=P0-1026483267-1284879945945"); request.BeginGetResponse(OnFileDownloadResponseReceived, new FileDownloadResponseReceivedUserState(request, callback, synoTrack)); }
public FileDownloadResponseReceivedUserState(HttpWebRequest request, Action <WebResponse, SynoTrack> getResponseCallback, SynoTrack synoTrack) { Request = request; GetResponseCallback = getResponseCallback; SynoTrack = synoTrack; }
public FileDownloadResponseReceivedUserState(HttpWebRequest request, Action<WebResponse, SynoTrack> getResponseCallback, SynoTrack synoTrack) { Request = request; GetResponseCallback = getResponseCallback; SynoTrack = synoTrack; }
public GuidToTrackMapping(Guid guid, SynoTrack track) : this() { Guid = guid; Track = track; }
/// <summary> /// Gets the remote file network stream. /// </summary> /// <param name="synoTrack">The track wor which to retrieve the stream.</param> /// <param name="callback">The method to call after the stream is open. The HttpResponse is passed as argument</param> /// <remarks>The caller is responsible for closing the stream after the call to DownloadFile returns</remarks> public void GetFileStream(SynoTrack synoTrack, Action<WebResponse, SynoTrack> callback) { if (synoTrack == null) { throw new ArgumentNullException("synoTrack"); } if (callback == null) { throw new ArgumentNullException("callback"); } var client = new WebClient(); // 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 & var relativePathToAudioStreamService = this.versionDependentResourcesProvider.GetAudioStreamWebserviceRelativePath(this.DsmVersion); string url = string.Format("http://{0}:{1}{2}/0.mp3?action=streaming&songpath={3}", this.Host, this.Port,relativePathToAudioStreamService, HttpUtility.UrlEncode(synoTrack.Res).Replace("+", "%20").Replace("&", "%26")); var request = (HttpWebRequest)WebRequest.Create(url); request.CookieContainer = new CookieContainer(); request.CookieContainer.SetCookies(new Uri(url), this.Token); //Set request headers. request.Accept = "application/x-ms-application, image/jpeg, application/xaml+xml, image/gif, image/pjpeg, application/x-ms-xbap, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*"; //request.Headers.Set(HttpRequestHeader.AcceptLanguage, "en-US"); //request.UserAgent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; InfoPath.2; OfficeLiveConnector.1.5; OfficeLivePatch.1.3; Zune 4.7)"; //request.Headers.Set(HttpRequestHeader.AcceptEncoding, "gzip, deflate"); //request.Headers.Set(HttpRequestHeader.Cookie, @"__utma=11735858.713408819.1284879944.1294622128.1297023459.8; __utmz=11735858.1297023459.8.8.utmcsr=google|utmccn=(organic)|utmcmd=organic|utmctr=TiltEffect%20Toolkit; __qca=P0-1026483267-1284879945945"); request.AllowReadStreamBuffering = false; request.BeginGetResponse(OnFileDownloadResponseReceived, new FileDownloadResponseReceivedUserState(request, callback, synoTrack)); }
public TrackViewModel Create(Guid guid, SynoTrack track, IPageSwitchingService pageSwitchingService) { return new TrackViewModel(guid, track, pageSwitchingService, _albumViewModelFactory, _session, _urlParameterToObjectsPlateHeater, this, notificationService); }
public DownloadFileState(Stream sourceStream, long bytesLeft, Stream targetStream,SynoTrack synoTrack, byte[] buffer, string filePath, long fileSize, Action<double> bufferingProgressUpdate) { if (sourceStream == null) { throw new ArgumentNullException("sourceStream"); } if (targetStream == null) { throw new ArgumentNullException("targetStream"); } if (buffer == null) { throw new ArgumentNullException("buffer"); } if (filePath == null) throw new ArgumentNullException("filePath"); if (bufferingProgressUpdate == null) { throw new ArgumentNullException("bufferingProgressUpdate"); } _fileSize = fileSize; SourceStream = sourceStream; BytesLeft = bytesLeft; TargetStream = targetStream; SynoTrack = synoTrack; Buffer = buffer; FilePath = filePath; FileSize = fileSize; BufferingProgressUpdate = bufferingProgressUpdate; }
public void StreamTrack(SynoTrack trackToPlay) { // 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?action=streaming&songpath={2}", _audioStationSession.Host, _audioStationSession.Port, HttpUtility.UrlEncode(trackToPlay.Res).Replace("+", "%20")); BackgroundAudioPlayer.Instance.Track = new AudioTrack(new Uri(url), trackToPlay.Title, trackToPlay.Artist, trackToPlay.Album, new Uri(trackToPlay.AlbumArtUrl)); BackgroundAudioPlayer.Instance.Play(); }
/// <summary> /// The heuristic used to define whether a given buffer can be played. /// </summary> /// <param name="track">The track being loaded.</param> /// <param name="loadedBytes">The amount of loaded bytes.</param> /// <returns></returns> /// <remarks>The method can be overrided, but the default predicate can also easily be replaced with the <see cref="BufferPlayableHeuristicPredicate"/> property.</remarks> public virtual bool BufferPlayableHeuristic(SynoTrack track, long loadedBytes) { return BufferPlayableHeuristicPredicate(track, loadedBytes); }
protected void OnTrackStarted(TrackStartedEventArgs trackStartedEventArgs) { _logService.Trace("PlaybackService.OnTrackStarted : " + trackStartedEventArgs.Track.Title); _lastStartedTrack = trackStartedEventArgs.Track; if (TrackStarted != null) { TrackStarted(this, trackStartedEventArgs); } }