Esempio n. 1
0
        // On change video state by server
        private void clientVideoStateChanged(object sender, ClientVideoEventArgs e)
        {
            Console.WriteLine("Changed by server, update local...");

            // if new file, try find in same dir
            Info info = player.GetInfo();

            if (info.FileName != e.file)
            {
                // if some file opened
                string openPath = null;
                if (info.FileDir.Length > 0)
                {
                    string newPath = Path.Combine(info.FileDir, e.file);
                    if (File.Exists(newPath))
                    {
                        openPath = newPath;
                    }
                }

                if (openPath != null)
                {
                    player.OpenFile(openPath);
                }
                else
                {
                    MessageBox.Show($"Please select {e.file}", "Open file", MessageBoxButton.OK, MessageBoxImage.Information);
                    OpenFileDialog openFileDialog = new OpenFileDialog();
                    openFileDialog.Filter = $"{e.file}|{e.file}|All files (*.*)|*.*";

                    if (openFileDialog.ShowDialog() == true)
                    {
                        string filePath = openFileDialog.FileName;

                        // Open file
                        player.OpenFile(filePath);
                        client.Get(Settings.Token, client.subscribedSessionIdentifer);
                    }
                }
            }

            player.SetPosition(e.position);
            player.SetState(e.state);
        }
Esempio n. 2
0
        void ProcessResponce(String responceString)
        {
            Console.WriteLine("Command: " + responceString);

            dynamic responce = JsonConvert.DeserializeObject(responceString);

            if (responce.status == "error")
            {
                Console.WriteLine($"Error: {responce.description} code: {responce.code}");

                if (onError != null)
                {
                    ClientErrorEventArgs args = new ClientErrorEventArgs();
                    args.code        = responce.code;
                    args.description = responce.description;
                    onError(this, args);
                }
            }

            if (responce.status == "ok")
            {
                Console.WriteLine($"Status: {responce.status} Command: {responce.command}");
            }

            if (responce.new_data != null)
            {
                EventHandler <ClientVideoEventArgs> handler = videoStateChanged;
                if (handler != null)
                {
                    ClientVideoEventArgs args = new ClientVideoEventArgs();
                    args.file     = responce.new_data.file;
                    args.position = TimeSpan.FromSeconds((double)responce.new_data.position);
                    args.state    = responce.new_data.state;
                    handler(this, args);
                }
            }
        }