Class that implements the ViewModel in MVVM pattern. This class contains the logic for playing audio stream using the Peer as point of access for the network.
Inheritance: INotifyPropertyChanged, IDisposable
Beispiel #1
0
        /// <summary>
        /// Handler for the drag and drop of the track thumb.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void TrackSlider_DragStarted(object sender, System.Windows.Controls.Primitives.DragStartedEventArgs e)
        {
            AudioPlayerModel vm = (AudioPlayerModel)this.DataContext;

            vm.EnableFlowRestart = false;
            vm.Pause.Execute(null);
        }
Beispiel #2
0
 /// <summary>
 /// Method called when the dialog is closing. This calls the dispose for the view model.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 void Dispatcher_ShutdownStarted(object sender, EventArgs e)
 {
     if (vm != null)
     {
         vm.Dispose();
         vm = null;
     }
 }
Beispiel #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void TrackSlider_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            Slider           s      = sender as Slider;
            Point            p      = e.GetPosition(s);
            AudioPlayerModel mv     = (AudioPlayerModel)this.DataContext;
            long             mySize = (long)((p.X / s.ActualWidth) * mv.ResourceTag.FileSize);

            mv.Position = mySize;
        }
Beispiel #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void TrackSlider_DragCompleted(object sender, System.Windows.Controls.Primitives.DragCompletedEventArgs e)
        {
            AudioPlayerModel vm = (AudioPlayerModel)this.DataContext;

            vm.EnableFlowRestart = true;
            Slider s = sender as Slider;

            Console.WriteLine("_________" + s.Value);
            if (!vm.CheckWaitingBuffering((long)s.Value))
            {
                vm.Pause.Execute(null);
            }
        }
Beispiel #5
0
        /// <summary>
        /// Default constructor. This constructor starts the splash in a different thread and the try to run the Peer.
        /// If the peer port is already in use a Peer Configuration dialog will be shown. If everything goes well the
        /// the model will be instantiated and the data context will be set. The splash screen will disappear when all
        /// GUI element have been loaded.
        /// </summary>
        public MainWindow()
        {
            bool keepTry = true;

            while (keepTry)
            {
                this.splashThread = new Thread(() =>
                {
                    System.Windows.Threading.Dispatcher.CurrentDispatcher.BeginInvoke((Action)(() => new AppSplashDialog().Show()));
                    System.Windows.Threading.Dispatcher.Run();
                });
                splashThread.SetApartmentState(ApartmentState.STA);
                splashThread.IsBackground = true;
                splashThread.Start();
                try
                {
                    peer = new Peer();
                    peer.RunLayers(true);
                    keepTry = false;
                }
                catch (SocketException aaiue)
                {
                    this.splashThread.Abort();
                    MessageBox.Show(aaiue.ToString(), "Peer initialization", MessageBoxButton.OK, MessageBoxImage.Error);
                    int udpPort = ((peer != null) ? int.Parse(peer.ConfOptions["udpPort"]) : 0);
                    int kadPort = ((peer != null) ? int.Parse(peer.ConfOptions["kadPort"]) : 0);
                    PeerConfigurationModel vm  = new PeerConfigurationModel(udpPort, kadPort);
                    PeerSettingsDialog     dlg = new PeerSettingsDialog();
                    dlg.DataContext = vm;
                    dlg.Activate();
                    dlg.ShowDialog();
                    if (dlg.DialogResult.HasValue && dlg.DialogResult.Value)
                    {
                        peer.Configure(vm.UdpPort.ToString(), vm.KademliaPort.ToString());
                        keepTry = true;
                    }
                    else
                    {
                        keepTry = false;
                    }
                }
                catch (FileNotFoundException)
                {
                    this.splashThread.Abort();
                    MessageBox.Show("Unable to find the file containing information about nodes. Download this file and retry.",
                                    "Peer initialization", MessageBoxButton.OK, MessageBoxImage.Error);
                    Environment.Exit(0);
                    keepTry = false;
                }
                catch (Exception e)
                {
                    this.splashThread.Abort();
                    MessageBox.Show(e.ToString(), "Peer initialization", MessageBoxButton.OK, MessageBoxImage.Error);
                    Environment.Exit(0);
                    keepTry = false;
                }
            }
            if (peer == null)
            {
                Environment.Exit(0);
            }
            playerModel = new AudioPlayerModel(peer);
            listModel   = new SearchListModel(peer);
            listModel.StreamRequested += playerModel.SetResourceHandler;
            this.InitializeComponent();
            object item = this.FindName("StreamPlayer");

            if ((item != null) && (item is AudioPlayer))
            {
                AudioPlayer p = item as AudioPlayer;
                p.SetDataContext(playerModel);
            }
            item = this.FindName("KadSearchList");
            if ((item != null))
            {
                SearchList s = item as SearchList;
                s.SetDataContext(listModel);
            }
        }
 /// <summary>
 /// Method called when the dialog is closing. This calls the dispose for the view model.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 void Dispatcher_ShutdownStarted(object sender, EventArgs e)
 {
     if (vm != null)
     {
         vm.Dispose();
         vm = null;
     }
 }
 /// <summary>
 /// Sets Data Context for this Control
 /// </summary>
 /// <param name="model">Model to be set</param>
 public void SetDataContext(AudioPlayerModel model)
 {
     vm = model;
     this.DataContext = vm;
 }
Beispiel #8
0
 /// <summary>
 /// Default constructor. This constructor starts the splash in a different thread and the try to run the Peer.
 /// If the peer port is already in use a Peer Configuration dialog will be shown. If everything goes well the
 /// the model will be instantiated and the data context will be set. The splash screen will disappear when all
 /// GUI element have been loaded.
 /// </summary>
 public MainWindow()
 {
     bool keepTry = true;
     while (keepTry)
     {
         this.splashThread = new Thread(() =>
         {
             System.Windows.Threading.Dispatcher.CurrentDispatcher.BeginInvoke((Action)(() => new AppSplashDialog().Show()));
             System.Windows.Threading.Dispatcher.Run();
         });
         splashThread.SetApartmentState(ApartmentState.STA);
         splashThread.IsBackground = true;
         splashThread.Start();
         try
         {
             peer = new Peer();
             peer.RunLayers(true);
             keepTry = false;
         }
         catch (SocketException aaiue)
         {
             this.splashThread.Abort();
             MessageBox.Show(aaiue.ToString(), "Peer initialization", MessageBoxButton.OK, MessageBoxImage.Error);
             int udpPort = ((peer != null) ? int.Parse(peer.ConfOptions["udpPort"]) : 0);
             int kadPort = ((peer != null) ? int.Parse(peer.ConfOptions["kadPort"]) : 0);
             PeerConfigurationModel vm = new PeerConfigurationModel(udpPort, kadPort);
             PeerSettingsDialog dlg = new PeerSettingsDialog();
             dlg.DataContext = vm;
             dlg.Activate();
             dlg.ShowDialog();
             if (dlg.DialogResult.HasValue && dlg.DialogResult.Value)
             {
                 peer.Configure(vm.UdpPort.ToString(), vm.KademliaPort.ToString());
                 keepTry = true;
             }
             else
             {
                 keepTry = false;
             }
         }
         catch (FileNotFoundException)
         {
             this.splashThread.Abort();
             MessageBox.Show("Unable to find the file containing information about nodes. Download this file and retry.",
                                 "Peer initialization", MessageBoxButton.OK, MessageBoxImage.Error);
             Environment.Exit(0);
             keepTry = false;
         }
         catch (Exception e)
         {
             this.splashThread.Abort();
             MessageBox.Show(e.ToString(), "Peer initialization", MessageBoxButton.OK, MessageBoxImage.Error);
             Environment.Exit(0);
             keepTry = false;
         }
     }
     if (peer == null) Environment.Exit(0);
     playerModel = new AudioPlayerModel(peer);
     listModel = new SearchListModel(peer);
     listModel.StreamRequested += playerModel.SetResourceHandler;
     this.InitializeComponent();
     object item = this.FindName("StreamPlayer");
     if ((item != null)&&(item is AudioPlayer))
     {
         AudioPlayer p = item as AudioPlayer;
         p.SetDataContext(playerModel);
     }
     item = this.FindName("KadSearchList");
     if ((item != null))
     {
         SearchList s = item as SearchList;
         s.SetDataContext(listModel);
     }
 }
Beispiel #9
0
 /// <summary>
 /// Sets Data Context for this Control
 /// </summary>
 /// <param name="model">Model to be set</param>
 public void SetDataContext(AudioPlayerModel model)
 {
     vm = model;
     this.DataContext = vm;
 }