/// <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;
        }
 protected void ClearInternalVariables()
 {
     _currentFileName = string.Empty;
     _currentItem = null;
     _nowPlaying = null;
     _station = null;
     _show = null;
 }
Example #3
0
 private void button5_Click(object sender, EventArgs e)
 {
     if (listView1.SelectedItems.Count > 0)
     {
         //StationNowPlayingListGetRequest req = new StationNowPlayingListGetRequest();
         //int i = 0;
         //int.TryParse(((RadioTimeOutline)listView1.SelectedItems[0].Tag).StationId, out i);
         //req.StationIds = new int[] { i };
         //propertyGrid1.SelectedObject = websrv.Station_NowPlayingListGet(req);
         var playing = new RadioTimeNowPlaying();
         playing.Grabber = grabber;
         playing.Get(((RadioTimeOutline) listView1.SelectedItems[0].Tag).GuidId,true);
     }
 }
        public void UpdatePlayProps()
        {
            // Log.Debug("*** UpdatePlayProps");
              try
              {
            if (!g_Player.Playing)
            {
              return;
            }

            PlayGuidId = (string.IsNullOrEmpty(PlayGuidId)) ? GUIPropertyManager.GetProperty("#RadioTime.Play.GuidId") : PlayGuidId;
            if (string.IsNullOrEmpty(PlayGuidId))
            {
              return;
            }

            _station = new RadioTimeStation();
            _station.Grabber = grabber;
            _station.Get(PlayGuidId);

            if (!string.IsNullOrEmpty(PlayGuidId) && _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) ;
              }
              //
              Settings.NowPlaying = _nowPlaying.Clone();
              Settings.NowPlayingStation = _station.Clone();
              if (_show != null)
              {
                Settings.NowPlayingShow = _show.Clone();
              }
              else
              {
                Settings.NowPlayingShow = null;
              }
              //
              UpdateProps();
            }
              }
              catch (Exception ex)
              {
            Log.Debug("UpdatePlayProps: " + ex.Message);
              }
        }
Example #5
0
 private void listView1_MouseDoubleClick(object sender, MouseEventArgs e)
 {
     if (listView1.SelectedItems.Count > 0)
     {
         textBox2.Text = ((RadioTimeOutline) listView1.SelectedItems[0].Tag).Url;
         grabber.GetData(((RadioTimeOutline) listView1.SelectedItems[0].Tag).Url);
         if (((RadioTimeOutline) listView1.SelectedItems[0].Tag).Type == RadioTimeOutline.OutlineType.audio)
         {
             var play = new RadioTimeNowPlaying();
             play.Get(((RadioTimeOutline) listView1.SelectedItems[0].Tag).StationId,true);
         }
         RefreshList();
     }
 }