public async Task SelectChannelByFrequencyAndMapPID(string frequencyAndMapPID) { _loggingService.Info($"Selecting channel by frequency and mapPID {frequencyAndMapPID}"); await Task.Run( () => { DVBTChannel firstChannel = null; DVBTChannel selectChannel = null; if (Channels.Count == 0) { return; } foreach (var ch in Channels) { if (firstChannel == null) { firstChannel = ch; } if (ch.Frequency.ToString() + ch.ProgramMapPID.ToString() == frequencyAndMapPID) { selectChannel = ch; break; } } if (selectChannel == null) { selectChannel = firstChannel; } SelectedChannel = selectChannel; }); }
private async Task Tune(long freq, long bandWidth, int dvbtTypeIndex) { try { //#if DEBUG // await Task.Delay(1000); // var channel = new DVBTChannel(); // channel.PIDs = "0,16,17"; // channel.ProgramMapPID = 5000; // channel.Name = "Channel name"; // channel.ProviderName = "Multiplex"; // channel.Frequency = freq; // channel.Bandwdith = bandWidth; // channel.Number = String.Empty; // channel.DVBTType = dvbtTypeIndex; // channel.Type = ServiceTypeEnum.DigitalTelevisionService; // TunedChannels.Add(channel); // Device.BeginInvokeOnMainThread(() => // { // SelectedChannel = channel; // }); //#endif var tuneResult = await _driver.TuneEnhanced(freq, bandWidth, dvbtTypeIndex); switch (tuneResult.Result) { case SearchProgramResultEnum.Error: _loggingService.Debug("Search error"); SignalStrengthProgress = 0; return; case SearchProgramResultEnum.NoSignal: _loggingService.Debug("No signal"); SignalStrengthProgress = 0; return; case SearchProgramResultEnum.OK: SignalStrengthProgress = tuneResult.SignalPercentStrength / 100.0; break; } var searchMapPIDsResult = await _driver.SearchProgramMapPIDs(false); switch (searchMapPIDsResult.Result) { case SearchProgramResultEnum.Error: _loggingService.Debug("Search error"); return; case SearchProgramResultEnum.NoSignal: _loggingService.Debug("No signal"); return; case SearchProgramResultEnum.NoProgramFound: _loggingService.Debug("No program found"); return; } var mapPIDs = new List <long>(); var mapPIDToServiceDescriptor = new Dictionary <long, ServiceDescriptor>(); foreach (var sd in searchMapPIDsResult.ServiceDescriptors) { mapPIDs.Add(sd.Value); mapPIDToServiceDescriptor.Add(sd.Value, sd.Key); } _loggingService.Debug($"Program MAP PIDs found: {String.Join(",", mapPIDs)}"); if (TuningAborted) { _loggingService.Debug($"Tuning aborted"); return; } // searching PIDs var searchProgramPIDsResult = await _driver.SearchProgramPIDs(mapPIDs); switch (searchProgramPIDsResult.Result) { case SearchProgramResultEnum.Error: _loggingService.Debug($"Error scanning Map PIDs"); break; case SearchProgramResultEnum.NoSignal: _loggingService.Debug("No signal"); break; case SearchProgramResultEnum.NoProgramFound: _loggingService.Debug("No program found"); break; case SearchProgramResultEnum.OK: var totalChannelsAddedCount = 0; foreach (var kvp in searchProgramPIDsResult.PIDs) { var pids = string.Join(",", kvp.Value); var sDescriptor = mapPIDToServiceDescriptor[kvp.Key]; var ch = new DVBTChannel(); ch.PIDs = pids; ch.ProgramMapPID = kvp.Key; ch.Name = sDescriptor.ServiceName; ch.ProviderName = sDescriptor.ProviderName; ch.Frequency = freq; ch.Bandwdith = bandWidth; ch.Number = String.Empty; ch.DVBTType = dvbtTypeIndex; ch.Type = (ServiceTypeEnum)sDescriptor.ServisType; TunedChannels.Add(ch); Device.BeginInvokeOnMainThread(() => { SelectedChannel = ch; }); _loggingService.Debug($"Found channel \"{sDescriptor.ServiceName}\""); // automatically adding new tuned channel if does not exist if (!ConfigViewModel.ChannelExists(_channels, ch.Frequency, ch.ProgramMapPID)) { ch.Number = ConfigViewModel.GetNextChannelNumber(_channels).ToString(); _channels.Add(ch); await _channelService.SaveChannels(_channels); totalChannelsAddedCount++; } } if (totalChannelsAddedCount > 0) { if (totalChannelsAddedCount > 1) { MessagingCenter.Send($"{totalChannelsAddedCount} channels saved", BaseViewModel.MSG_ToastMessage); } else { MessagingCenter.Send($"Channel saved", BaseViewModel.MSG_ToastMessage); } } break; } } catch (Exception ex) { throw; } }
public async Task ActionPlay(DVBTChannel channel = null) { if (channel == null) { channel = _viewModel.SelectedChannel; } if (channel == null) { return; } if (PlayingState == PlayingStateEnum.Recording) { MessagingCenter.Send($"Playing {channel.Name} failed (recording in progress)", BaseViewModel.MSG_ToastMessage); return; } if (PlayingState == PlayingStateEnum.PlayingInPreview && _viewModel.PlayingChannel == channel) { PlayingState = PlayingStateEnum.Playing; return; } Device.BeginInvokeOnMainThread(() => { if (PlayingState == PlayingStateEnum.Playing || PlayingState == PlayingStateEnum.PlayingInPreview) { videoView.MediaPlayer.Stop(); } }); if (!_driver.Started) { MessagingCenter.Send($"Playing {channel.Name} failed (device connection error)", BaseViewModel.MSG_ToastMessage); return; } var playRes = await _driver.Play(channel.Frequency, channel.Bandwdith, channel.DVBTType, channel.PIDsArary); if (!playRes.OK) { MessagingCenter.Send($"Playing {channel.Name} failed (device connection error)", BaseViewModel.MSG_ToastMessage); return; } Device.BeginInvokeOnMainThread(() => { if (_driver.VideoStream != null) { _media = new Media(_libVLC, _driver.VideoStream, new string[] { }); videoView.MediaPlayer.Play(_media); } }); var playInfo = new PlayStreamInfo { Channel = channel, SignalStrengthPercentage = playRes.SignalStrengthPercentage }; var eitManager = _driver.GetEITManager(channel.Frequency); if (eitManager != null) { playInfo.CurrentEvent = eitManager.GetEvent(DateTime.Now, Convert.ToInt32(channel.ProgramMapPID)); } ShowActualPlayingMessage(playInfo); if (_config.PlayOnBackground) { MessagingCenter.Send <MainPage, PlayStreamInfo>(this, BaseViewModel.MSG_PlayInBackgroundNotification, playInfo); } _viewModel.PlayingChannel = channel; PlayingState = PlayingStateEnum.Playing; }
public async Task PlayChannel(DVBTChannel channel = null) { if (channel == null) { channel = SelectedChannel; if (channel == null) { return; } } var playInfo = new PlayStreamInfo { Channel = channel }; if (_recordingChannel != null) { MessagingCenter.Send($"Playing {channel.Name} failed (recording in progress)", BaseViewModel.MSG_ToastMessage); return; } _loggingService.Debug($"Playing channel {channel}"); try { if (!_driver.Started) { MessagingCenter.Send($"Playing {channel.Name} failed (device connection error)", BaseViewModel.MSG_ToastMessage); return; } IsRefreshing = true; var playRes = await _driver.Play(channel.Frequency, channel.Bandwdith, channel.DVBTType, channel.PIDsArary); if (!playRes.OK) { throw new Exception("Play returned false"); } playInfo.SignalStrengthPercentage = playRes.SignalStrengthPercentage; var eitManager = _driver.GetEITManager(channel.Frequency); if (eitManager != null) { playInfo.CurrentEvent = eitManager.GetEvent(DateTime.Now, Convert.ToInt32(channel.ProgramMapPID)); } MessagingCenter.Send(playInfo, BaseViewModel.MSG_PlayStream); } catch (Exception ex) { _loggingService.Error(ex, $"Playing {channel.Name} failed"); MessagingCenter.Send($"Playing {channel.Name} failed", BaseViewModel.MSG_ToastMessage); } finally { IsRefreshing = false; } }
public async Task ScanEPG(DVBTChannel channel) { if (channel == null) { channel = SelectedChannel; if (channel == null) { return; } } if (_recordingChannel != null) { MessagingCenter.Send($"Cannot scan EPG (recording in progress)", BaseViewModel.MSG_ToastMessage); return; } _loggingService.Debug($"Scanning EPG for channel {channel}"); try { if (!_driver.Started) { MessagingCenter.Send($"Cannot scan EPG (device connection error)", BaseViewModel.MSG_ToastMessage); return; } await Task.Run(async() => { MessagingCenter.Send($"Scanning EPG ....", BaseViewModel.MSG_LongToastMessage); var tuned = await _driver.TuneEnhanced(channel.Frequency, channel.Bandwdith, channel.DVBTType); if (tuned.Result != SearchProgramResultEnum.OK) { MessagingCenter.Send($"Scanning EPG failed", BaseViewModel.MSG_ToastMessage); return; } // setting PID 18 + PSI for each channel in the same multiplex: var res = await _driver.ScanEPG(channel.Frequency, 5000); await _driver.Stop(); await RefreshEPG(); var msg = String.Empty; if (!res.OK) { msg += "EPG scan failed"; } if (res.UnsupportedEncoding) { if (msg != String.Empty) { msg += ", unsupported encoding found"; } else { msg = "Unsupported encoding found"; } } if (!string.IsNullOrEmpty(msg)) { MessagingCenter.Send(msg, BaseViewModel.MSG_ToastMessage); } }); } catch (Exception ex) { _loggingService.Error(ex, $"EPG scan failed"); MessagingCenter.Send($"EPG scan failed", BaseViewModel.MSG_ToastMessage); } }
private async Task RecordChannel(DVBTChannel channel, bool start) { if (channel == null) { channel = SelectedChannel; if (channel == null) { return; } } _loggingService.Debug($"Recording channel {channel}: {start}"); try { if (start) { if (!_driver.Started) { MessagingCenter.Send($"Recording failed (device connection error)", BaseViewModel.MSG_ToastMessage); return; } var playRes = await _driver.Play(channel.Frequency, channel.Bandwdith, channel.DVBTType, channel.PIDsArary, false); if (!playRes.OK) { throw new Exception("Play returned false"); } _recordingChannel = channel; channel.Recording = true; await _driver.StartRecording(); MessagingCenter.Send($"Recording started", BaseViewModel.MSG_ToastMessage); } else { if (!_driver.Started) { MessagingCenter.Send($"Stop recording failed (device connection error)", BaseViewModel.MSG_ToastMessage); return; } _driver.StopRecording(); await _driver.Stop(); _recordingChannel = null; channel.Recording = false; MessagingCenter.Send($"Recording stopped", BaseViewModel.MSG_ToastMessage); } } catch (Exception ex) { _loggingService.Error(ex); MessagingCenter.Send($"Start/stop recording failed (device connection error)", BaseViewModel.MSG_ToastMessage); return; } channel.NotifyRecordingLabelChange(); }
public async Task ShowChannelMenu(DVBTChannel ch = null) { if (ch == null) { ch = SelectedChannel; } if (ch == null) { await _dialogService.Information("No channel selected"); return; } var actions = new List <string>(); if (!ch.Recording) { actions.Add("Play"); actions.Add("Scan EPG"); actions.Add("Detail & edit"); actions.Add("Record"); actions.Add("Delete"); } else { actions.Add("Show record location"); actions.Add("Stop record"); } var action = await _dialogService.DisplayActionSheet($"{ch.Name}", "Cancel", actions); switch (action) { case "Play": await PlayChannel(ch); break; case "Scan EPG": await ScanEPG(ch); break; case "Detail & edit": MessagingCenter.Send(ch.ToString(), BaseViewModel.MSG_EditChannel); break; case "Record": await RecordChannel(ch, true); break; case "Show record location": await _dialogService.Information(_driver.RecordFileName); break; case "Stop record": await RecordChannel(ch, false); break; case "Delete": await DeleteChannel(ch); break; } }