示例#1
0
        private void bgwGetURI_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker worker = sender as BackgroundWorker;
            string           uri    = e.Argument.ToString();

            if (worker.CancellationPending)
            {
                Logger.Info("Cancelling work.");
                return;
            }

            MediaKlikk mediaKlikk = new MediaKlikk();

            try
            {
                Uri url = new Uri(mediaKlikk.GetChannelURI(currentChannel));

                if (worker.CancellationPending)
                {
                    Logger.Info("Cancelling work.");
                    return;
                }
                Logger.Info(string.Format("URI={0}", url));

                e.Result = url;
            }
            catch (Exception ex)
            {
                Logger.Warning(String.Format("Unable to play stream, {0}. {1}", uri, ex.Message));
                Logger.Error(ex);
            }
        }
示例#2
0
        private void bgwRecording_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker backgroundWorker = sender as BackgroundWorker;
            Channel          channel          = (Channel)e.Argument;
            VideoMetadata    videoMetadata    = new VideoMetadata();

            try
            {
                // Check if current channel is playing before trying to record
                if (currentChannel.IsPlaying)
                {
                    var currentDirectory = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
                    var libDirectory     = new DirectoryInfo(Path.Combine(currentDirectory, "libvlc", IntPtr.Size == 4 ? "win-x86" : "win-x64"));
                    var destinationDir   = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyVideos), "MagyarTV");
                    if (!File.Exists(destinationDir))
                    {
                        try
                        {
                            Directory.CreateDirectory(destinationDir);
                        }
                        catch (Exception ex)
                        {
                            Logger.Error(ex);
                        }
                    }
                    var destination = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyVideos), "MagyarTV", channel.StreamInfo.Title + "_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".ts");
                    /// New definition of mediaPlayer
                    using (var mediaRecorder = new Vlc.DotNet.Core.VlcMediaPlayer(libDirectory))
                    {
                        var mediaOptions = new[]
                        {
                            ":sout=#file{dst=" + destination + "}",
                            ":sout-keep"
                        };
                        currentChannel.IsRecording = true;
                        MediaKlikk mediaKlikk = new MediaKlikk();
                        mediaRecorder.SetMedia(new Uri(mediaKlikk.GetChannelURI(currentChannel)), mediaOptions);
                        btRecord.ForeColor = Color.Red;
                        mediaRecorder.Play();
                        currentRecording.Channel = channel;
                        Logger.Info(String.Format("Recording channel {0} to {1}.", currentChannel.Name, destination));
                        if (backgroundWorker != null)
                        {
                            while (!backgroundWorker.CancellationPending)
                            {
                                // Update
                            }
                            if (backgroundWorker.CancellationPending)
                            {
                                Logger.Info(String.Format("Cancelled recording channel {0}.", currentChannel.Name));
                                btRecord.ForeColor = Color.Black;
                                e.Cancel           = true;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error("Failed to start recording");
                Logger.Error(ex);
                MessageBox.Show(String.Format("Failed to start recording. {0}", ex.Message));
            }
        }