public void SetStation(TvStation tvStation)
 {
     if (tvStation?.FileUrl == null)
     {
         try
         {
             if (this.mediaElement.Source != null)
             {
                 this.mediaElement.Stop();
             }
         }
         catch
         {
         }
         this.mediaElement.Source = null;
     }
     else
     {
         this.mediaElement.Source = tvStation.FileUrl;
         this.UpdateProgress();
     }
     if (tvStation != null)
     {
         this.ToggleStationIndicator();
     }
     else
     {
         this.hideStationIndicatorAction?.ExecuteAsync()?.ContinueWith(t => t?.Result?.Dispose());
     }
 }
Example #2
0
 public StationEntity(int index, string name, TvStation station)
     : base("station")
 {
     this.Index   = index;
     this.Value   = name;
     this.Station = station;
 }
Example #3
0
        private ApiTvStation MapStation(TvStation station)
        {
            var     apiTvStation = Mapper.Map <ApiTvStation>(station);
            dynamic parameters   = new { id = station.Id };
            Uri     image        = this.resourceLinker.BuildAbsoluteUri(this.Context, "StationImageRoute", parameters);

            apiTvStation.Image = image.OriginalString;
            return(apiTvStation);
        }
Example #4
0
        public bool SetCurrentStation(TvStation selected)
        {
            if (selected != null)
            {
                this.SelectedIndex = this.TvStations.IndexOf(selected);
                return(true);
            }

            this.SelectedIndex = -1;

            return(true);
        }
Example #5
0
        public TvStationsModule(ITvStations tvStations, IResourceLinker resourceLinker)
            : base("tvstations")
        {
            this.resourceLinker = resourceLinker;
            this.Get["/", true] = async(o, token) =>
            {
                TvStation[] stations = await tvStations.GetAllAsync();

                List <ApiTvStation> apiTvStations   = stations.Select(station => this.MapStation(station)).ToList();
                TvStation           selectedStation = TvControlViewModel.Current.SelectedStation;
                return(new {
                    Stations = apiTvStations,
                    Selected = selectedStation == null ? null : this.MapStation(selectedStation),
                    TvControlViewModel.Current.SelectedIndex
                });
            };

            this.Post["/{id}"] = o =>
            {
                TvControlViewModel tvControlViewModel = TvControlViewModel.Current;
                if (!tvControlViewModel.SetCurrentStation(o.id))
                {
                    return(InvalidStationIdResponse(o.id));
                }

                return(HttpStatusCode.Accepted);
            };

            this.Post["/toggleInfo"] = o =>
            {
                TvControlViewModel.Current.ToggleInfoCommand.Execute();
                return(HttpStatusCode.Accepted);
            };

            this.Get["StationImageRoute", "/image/{id}"] = o =>
            {
                dynamic   id      = o.id;
                TvStation station = TvControlViewModel.Current.TvStations.FirstOrDefault(s => s.Id == id);
                var       encoder = new PngBitmapEncoder();
                if (station == null)
                {
                    return(InvalidStationIdResponse(o.id));
                }

                var stationImage = (BitmapSource)station.Image;
                encoder.Frames.Add(BitmapFrame.Create(stationImage));

                var stream = new MemoryStream();
                encoder.Save(stream);
                byte[] bitmapdata = stream.ToArray();
                return(new ByteArrayResponse(bitmapdata, "image/png"));
            };
        }
Example #6
0
        public void AppendVideoFile(TvStation station, string filePath)
        {
            var    fileInfo = new FileInfo(filePath);
            string stationId;

            if (!this.TryGetStationId(filePath, out stationId))
            {
                string extension = Path.GetExtension(filePath);
                string fileName  = Path.GetFileNameWithoutExtension(filePath);
                fileInfo.Rename(fileName + "_station_" + station.Id + "_" + extension);
            }
            SetFileProperties(station, filePath);
        }
 public async Task ToggleInfoAsync(TvStation station, bool show)
 {
     this.hideStationIndicatorAction?.Dispose();
     if (!show)
     {
         this.window.StationIndicator.Visibility = Visibility.Collapsed;
     }
     else
     {
         TimeSpan showTime = TimeSpan.FromSeconds(20);
         await this.ToggleStationInfo(showTime);
     }
 }
Example #8
0
        public void AppendVideoFiles(TvStation station, string[] files)
        {
            int index = this.TvStations.IndexOf(station);

            foreach (string file in files)
            {
                TvStation tvStation;
                string    stationId;
                if (this.TryGetStationId(file, out stationId))
                {
                    tvStation = this.TvStations.FirstOrDefault(s => s.Id == stationId);
                    if (tvStation != null)
                    {
                        SetFileProperties(tvStation, file);
                        continue;
                    }
                }

                tvStation = this.TvStations[index];
                SetFileProperties(tvStation, file);
                index++;
            }
        }
Example #9
0
        public TvControlViewModel(ITvStations tvStations, IPlaybackControl control)
        {
            this.tvStations = tvStations;
            this.control    = control;

            Current = this;

            this.InitAsync();
            this.Volume = control.Volume;

            this.WhenAnyValue(model => model.SelectedIndex)
            //.Where(i => i >= 0)
            .ObserveOnDispatcher()
            .Select(i => this.TvStations.ElementAtOrDefault(i))
            .ToProperty(this, model => model.SelectedStation, out this.selectedStation);

            this.WhenAnyValue(model => model.SelectedStation).ObserveOnDispatcher().Subscribe(station => { this.control.SetStation(station); });

            this.WhenAnyValue(model => model.Volume).Subscribe(vol => this.DisplayVolume = Math.Round(100 * vol, 0, MidpointRounding.AwayFromZero).ToString());

            this.ChangeStationCommand = ReactiveCommand.Create <int>(dir =>
            {
                int newIndexAbsolute = this.SelectedIndex + (dir > 0 ? 1 : -1);
                this.SelectedIndex   = newIndexAbsolute < 0 ? this.TvStations.Count - 1 : newIndexAbsolute >= this.TvStations.Count ? 0 : newIndexAbsolute;
            });

            this.ChangeVolumeCommand = ReactiveCommand.Create <int, Unit>(dir =>
            {
                RxApp.MainThreadScheduler.Schedule(() => { this.Volume = this.control.ChangeVolume(dir); });
                return(Unit.Default);
            });

            this.ToggleInfoCommand = ReactiveCommand.Create <TvStation, Unit>(station =>
            {
                station          = station ?? this.SelectedStation;
                bool show        = !(this.infoStation?.Id?.Equals(station?.Id) ?? false);
                this.infoStation = station;

                RxApp.MainThreadScheduler.Schedule(async() =>
                {
                    try
                    {
                        await this.control.ToggleInfoAsync(station, show);
                    }
                    catch
                    {
                    }
                    this.infoStation = null;
                });

                return(Unit.Default);
            });

            this.ToggleOnOff = ReactiveCommand.Create(() =>
            {
                var isOn = this.SelectedStation != null;
                if (isOn)
                {
                    this.SelectedIndex = -1;
                }
                else
                {
                    this.SelectedIndex = 0;
                }
            });
        }
Example #10
0
        public bool SetCurrentStation(string id)
        {
            TvStation selected = this.TvStations.FirstOrDefault(station => station.Id == id);

            return(this.SetCurrentStation(selected));
        }
Example #11
0
 private static void SetFileProperties(TvStation tvStation, string file)
 {
     tvStation.FileUrl  = new Uri(file);
     tvStation.FileName = tvStation.FileUrl.Segments.LastOrDefault();
 }