/// <summary>
        /// Does the play.
        /// </summary>
        /// <param name="item">The item.</param>
        public void DoPlay(RadioTimeOutline item)
        {
            ShowWaitCursor();
            try
            {
                _station = null;
                _nowPlaying = null;
                _show = null;
                _currentItem = null;

                if (item == null || string.IsNullOrEmpty(item.GuidId))
                {
                    ErrMessage(Translation.StationNotAvaiable);
                    return;
                }
                PlayGuidId = item.GuidId ;
                _currentItem = item.Clone();

                //RadioTimeStation station = Settings.NowPlayingStation;
                _station = new RadioTimeStation();
                _station.Grabber = grabber;
                _station.Get(PlayGuidId);

                if (_station.IsAvailable)
                {
                    //var nowPlaying = Settings.NowPlaying;
                    _nowPlaying = new RadioTimeNowPlaying();
                    _nowPlaying.Grabber = grabber;
                    _nowPlaying.Get(PlayGuidId, _station.HasSong);

                    if (_nowPlaying.IsShow && !string.IsNullOrEmpty(_nowPlaying.ShowGuidId))
                    {
                        _show = new RadioTimeShow();
                        _show.Grabber = grabber;
                        _show.Get(_nowPlaying.ShowGuidId) ;
                    }

                    var playerType = PlayerType.Video;
                    if (_setting.FormatPlayer.ContainsKey(item.Formats))
                        playerType = _setting.FormatPlayer[item.Formats];

                    try
                    {
                        var playList = new PlayList();
                        //if (item.Url.ToLower().Contains(".pls") || item.Url.ToLower().Contains(".m3u") || item.Url.ToLower().Contains(".asx"))
                        {
                            var TargetFile = Path.GetTempFileName();
                            var client = new WebClient();
                            try
                            {
                                if (item.Url.ToLower().Contains(".pls"))
                                {
                                    client.DownloadFile(item.Url, TargetFile);
                                    IPlayListIO loader = new PlayListPLSEIO();
                                    loader.Load(playList, TargetFile);
                                }
                                else if (item.Url.ToLower().Contains(".asx"))
                                {
                                    client.DownloadFile(item.Url, TargetFile);
                                    IPlayListIO loader = new PlayListASXIO();
                                    loader.Load(playList, TargetFile);
                                }
                                else
                                {
                                    client.DownloadFile(item.Url, TargetFile);
                                    IPlayListIO loader = new PlayListM3uIO();
                                    loader.Load(playList, TargetFile);
                                }
                            }
                            finally
                            {
                                client.Dispose();
                                File.Delete(TargetFile);
                            }

                            //if (playList.Count > 0 && playList[0].FileName.ToLower().StartsWith("http") && playList[0].FileName.ToLower().Contains(".m3u"))
                            //{
                            //  client.DownloadFile(playList[0].FileName, TargetFile);
                            //  IPlayListIO loader1 = new PlayListM3uIO();
                            //  loader1.Load(playList, TargetFile);
                            //  File.Delete(TargetFile);
                            //}

                            TargetFile = Path.GetTempFileName();
                            client = new WebClient();
                            try
                            {
                                if (playList.Count > 0 && playList[0].FileName.ToLower().Contains(".pls"))
                                {
                                    client.DownloadFile(playList[0].FileName, TargetFile);
                                    IPlayListIO loader1 = new PlayListPLSEIO();
                                    loader1.Load(playList, TargetFile);
                                }

                                if (playList.Count > 0 && playList[0].FileName.ToLower().Contains(".asx"))
                                {
                                    client.DownloadFile(playList[0].FileName, TargetFile);
                                    IPlayListIO loader1 = new PlayListASXIO();
                                    loader1.Load(playList, TargetFile);
                                }

                                if (playList.Count > 0 && playList[0].FileName.ToLower().Contains(".m3u"))
                                {
                                    client.DownloadFile(playList[0].FileName, TargetFile);
                                    IPlayListIO loader1 = new PlayListM3uIO();
                                    loader1.Load(playList, TargetFile);
                                    if (playList.Count == 0)
                                    {
                                        IPlayListIO loader2 = new PlayListPLSEIO();
                                        loader2.Load(playList, TargetFile);
                                    }
                                }
                            }
                            finally
                            {
                                client.Dispose();
                                File.Delete(TargetFile);
                            }
                        }

                        if (playList.Count > 0)
                            _currentFileName = playList[0].FileName;
                        else
                            _currentFileName = item.Url;

                        switch (playerType)
                        {
                            case PlayerType.Audio:
                                ClearPlayProps();
                                g_Player.PlayAudioStream(_currentFileName);
                                return;
                            case PlayerType.Video:
                                // test if the station have tv group
                                ClearPlayProps();
                                if (item.GenreId == "g260" || item.GenreId == "g83" || item.GenreId == "g374" ||
                                    item.GenreId == "g2769")
                                    g_Player.PlayVideoStream(_currentFileName);
                                else
                                    g_Player.Play(_currentFileName, g_Player.MediaType.Unknown);
                                return;
                            case PlayerType.Unknow:
                                return;
                            default:
                                return;
                        }
                        // moved to PLAYBACKSTARTED EVENT
                        //if  (isPlaying && g_Player.CurrentFile == playList[0].FileName)
                    }
                    catch (Exception exception)
                    {
                        _currentItem = null;
                        ErrMessage(string.Format(Translation.PlayError, exception.Message));
                        return;
                    }
                }
            }
            finally
            {
                HideWaitCursor();
            }
            ErrMessage(Translation.StationNotAvaiable);
            return;
        }
Exemple #2
0
 private string DownloadFile(RadioTimeOutline radioItem)
 {
     string localFile = GetLocalImageFileName(radioItem.Image.Replace("q.png", ".png"));
       if (!File.Exists(localFile) && !string.IsNullOrEmpty(radioItem.Image))
       {
     downloaQueue.Enqueue(new DownloadFileObject(localFile, radioItem.Image.Replace("q.png", ".png")));
       }
       return localFile;
 }
 protected void ClearInternalVariables()
 {
     _currentFileName = string.Empty;
     _currentItem = null;
     _nowPlaying = null;
     _station = null;
     _show = null;
 }
        public void UpdateSelectedLabels(RadioTimeOutline radioItem)
        {
            GUIPropertyManager.SetProperty("#RadioTime.Selected.NowPlaying", radioItem.CurrentTrack);
            string subtext = radioItem.Subtext;
            if (GUIPropertyManager.GetProperty("#RadioTime.Play.HasSong").Equals("true"))
            {
              PlayGuidId = (string.IsNullOrEmpty(PlayGuidId)) ? GUIPropertyManager.GetProperty("#RadioTime.Play.GuidId") : PlayGuidId;
              if (!string.IsNullOrEmpty(PlayGuidId) && radioItem.GuidId.Equals(PlayGuidId))
              {
                string artist = GUIPropertyManager.GetProperty("#Play.Current.Artist");
                // string album = GUIPropertyManager.GetProperty("#Play.Current.Album");
                string track = GUIPropertyManager.GetProperty("#Play.Current.Title");
                if (!string.IsNullOrEmpty(artist))
                {
                  // subtext = string.Empty + artist + (!string.IsNullOrEmpty(album) ? " - " : "") + album + (!string.IsNullOrEmpty(track) ? " - " : "") + track; // FH not compatible with Artist - Album - Track
                  subtext = string.Empty + artist + (!string.IsNullOrEmpty(track) ? " - " : "") + track;
                }
              }
            }
            GUIPropertyManager.SetProperty("#RadioTime.Selected.Subtext", subtext);
            GUIPropertyManager.SetProperty("#RadioTime.Selected.Reliability", (radioItem.ReliabilityIdAsInt/10).ToString());

            GUIPropertyManager.SetProperty("#RadioTime.Selected.Logo", string.Empty);
            GUIPropertyManager.SetProperty("#RadioTime.Selected.Logo", DownloadStationLogo(radioItem));

            if (_setting.FormatNames.ContainsKey(radioItem.Formats))
                GUIPropertyManager.SetProperty("#RadioTime.Selected.Format", _setting.FormatNames[radioItem.Formats]);
            else
                GUIPropertyManager.SetProperty("#RadioTime.Selected.Format", string.Empty);
            Process();
        }
 public string GetStationLogoFileName(RadioTimeOutline radioItem)
 {
     if (string.IsNullOrEmpty(radioItem.Image))
         return string.Empty;
     return Utils.GetCoverArtName(Thumbs.Radio, radioItem.Text);
 }
 public string DownloadStationLogo(RadioTimeOutline radioItem)
 {
     var localFile = GetStationLogoFileName(radioItem);
     if (!File.Exists(localFile) && !string.IsNullOrEmpty(radioItem.Image))
     {
         // downloaQueue.Enqueue(new DownloadFileObject(localFile, radioItem.Image.Replace("q.png", ".png")));
         downloaQueue.Enqueue(new DownloadFileObject(localFile, radioItem.Image));
     }
     return localFile;
 }
Exemple #7
0
        public void UpdateSelectedLabels(RadioTimeOutline radioItem)
        {
            GUIPropertyManager.SetProperty("#RadioTime.Selected.NowPlaying", radioItem.CurrentTrack);
              GUIPropertyManager.SetProperty("#RadioTime.Selected.Subtext", radioItem.Subtext);
              GUIPropertyManager.SetProperty("#RadioTime.Selected.Reliability", (radioItem.ReliabilityIdAsInt / 10).ToString());

              GUIPropertyManager.SetProperty("#RadioTime.Selected.Logo", " ");
              GUIPropertyManager.SetProperty("#RadioTime.Selected.Logo", DownloadStationLogo(radioItem));

              if (_setting.FormatNames.ContainsKey(radioItem.Formats))
            GUIPropertyManager.SetProperty("#RadioTime.Selected.Format", _setting.FormatNames[radioItem.Formats]);
              else
            GUIPropertyManager.SetProperty("#RadioTime.Selected.Format", " ");
              Process();
        }