private void LoadPreviousClip() { NovatekFile previousClip = SelectedTrip.Clips.Where(x => x.FileName == SelectedTrip.CurrentClip.PreviousFile).SingleOrDefault(); // Check the player has a clip loaded if (SparePlayer.HasVideo && _spClip == previousClip && SparePlayer.NaturalDuration.HasTimeSpan) { // Match the SpeedRatio and Volume SparePlayer.SpeedRatio = CurrentPlayer.SpeedRatio; SparePlayer.Volume = CurrentPlayer.Volume; // Show the spare player SparePlayer.Visibility = Visibility.Visible; CurrentPlayer.Visibility = Visibility.Hidden; SparePlayer.Play(); CurrentPlayer.Pause(); // Set the maximum of the position bar UI.FindChild <Slider>(Application.Current.MainWindow, "posSlider").Maximum = SparePlayer.NaturalDuration.TimeSpan.TotalSeconds; // Switch the current player with spare var spare = SparePlayer; var current = CurrentPlayer; CurrentPlayer = spare; SparePlayer = current; // Update the curernt clip SelectedTrip.CurrentClip = previousClip; } else if (!string.IsNullOrEmpty(SelectedTrip.CurrentClip.PreviousFile)) { PreparePreviousClip(); Thread.Sleep(10); LoadPreviousClip(); } }
private void ExtractClip(string fileWithPath, string outputDirectory) { string SafeFileName = Path.GetFileNameWithoutExtension(fileWithPath); string outputFile = outputDirectory + @"\" + Path.GetFileNameWithoutExtension(fileWithPath) + ".gpx"; NovatekFile file = _selectedTrip.Clips.Where(c => c.FullNameAndPath == fileWithPath).Single(); // GPX template string gpx; gpx = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"; gpx += "<gpx version=\"1.0\" "; gpx += "creator=\"NovaTrakt by PAW Soft\" "; gpx += "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "; gpx += "xmlns=\"http://www.topografix.com/GPX/1/0\" "; gpx += "xsi:schemaLocation=\"http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd\">\r\n"; gpx += "\t<name>" + SafeFileName + "</name>\r\n"; gpx += "\t<url>http://novatrakt.pawsoft.co.uk</url>\r\n"; gpx += "\t<trk>\r\n"; gpx += "\t<name>" + SafeFileName + "</name>\r\n"; gpx += "\t<trkseg>\r\n"; foreach (GPSData gps in file.AllGPSData) { gpx += "\t\t<trkpt lat=\"" + gps.Latitude.ToString(CultureInfo.InvariantCulture) + "\" " + "lon=\"" + gps.Longitude.ToString(CultureInfo.InvariantCulture) + "\">" + "<time>" + String.Format("{0:s}", gps.DateTime) + "</time>" + "<speed>" + gps.Speed.ToString(CultureInfo.InvariantCulture) + "</speed></trkpt>\r\n"; } gpx += "\t</trkseg>\r\n"; gpx += "\t</trk>\r\n"; gpx += "</gpx>\n"; // Write to GPX file try { // Delete the file if it exists. if (File.Exists(outputFile)) { File.Delete(outputFile); } // Create the file. using (FileStream fs = File.Create(outputFile)) { Byte[] info = new UTF8Encoding(true).GetBytes(gpx); // Add some information to the file. fs.Write(info, 0, info.Length); } // DEBUG: Completed Message Log.WriteLine("Info", "GPX file (" + outputFile + ") created!"); } catch (Exception ex) { Log.WriteLine("ERROR", "Unable to create GPX file: " + outputFile); MessageBox.Show(ex.ToString()); } }
private void PreparePreviousClip() { if (!string.IsNullOrEmpty(SelectedTrip.CurrentClip.PreviousFile)) { // Load the next file into the spare player NovatekFile previous = SelectedTrip.Clips.Where(x => x.FileName == SelectedTrip.CurrentClip.PreviousFile).SingleOrDefault(); SparePlayer.Source = new Uri(previous.FullNameAndPath); SparePlayer.Play(); SparePlayer.Pause(); _spClip = previous; } }
private void OpenWorker_DoWork(object sender, DoWorkEventArgs e) { // Force this thread to work in EN Culture Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en"); // Get all the MP4 files in the chosen directory string[] inputFiles; string[] inputFolder = Directory.GetFiles(_inputPath, "*.mp4"); if (Directory.Exists(_inputPath + @"\RO")) { string[] inputFolderRO = Directory.GetFiles(_inputPath + @"\RO", "*.mp4"); inputFiles = inputFolder.Concat(inputFolderRO).ToArray(); } else { Log.WriteVerboseLine("RO Directory does not exist."); inputFiles = inputFolder; } // Set the progress status _progressDlg.Maximum = inputFiles.Count(); double count = 0; // Clear existing list of clips _clips.Clear(); Application.Current.Dispatcher.BeginInvoke(new Action(() => _journeyList.Clear())); foreach (string file in inputFiles) { Log.WriteLine("Info", "Loading file " + file); FileInfo fileInfo = new FileInfo(file); NovatekFile _file = new NovatekFile(fileInfo.DirectoryName, fileInfo.Name); if (_file.MoovBox != 0) { Log.WriteVerboseLine("File is a valid MP4 video file."); _clips.Add(_file); } else { Log.WriteLine("ERROR", "File at " + file + " does not seem to be a valid video file. File will be ignored."); } _progressDlg.SetProgress(count++); } }
private async void ExtractClip(string fileWithPath) { // Ask where to save the file SaveFileDialog saveDlg = new SaveFileDialog(); saveDlg.FileName = Path.GetFileNameWithoutExtension(fileWithPath); saveDlg.DefaultExt = ".gpx"; saveDlg.Filter = "GPS Exchange Format|*.gpx"; // Show the save dialog box Nullable <bool> result = saveDlg.ShowDialog(); // Process the save file if (result == true && Path.GetExtension(saveDlg.FileName) == ".gpx") { NovatekFile file = _selectedTrip.Clips.Where(c => c.FullNameAndPath == fileWithPath).Single(); // GPX template string gpx; gpx = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"; gpx += "<gpx version=\"1.0\" "; gpx += "creator=\"NovaTrakt by PAW Soft\" "; gpx += "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "; gpx += "xmlns=\"http://www.topografix.com/GPX/1/0\" "; gpx += "xsi:schemaLocation=\"http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd\">\r\n"; gpx += "\t<name>" + saveDlg.SafeFileName + "</name>\r\n"; gpx += "\t<url>http://novatrakt.pawsoft.co.uk</url>\r\n"; gpx += "\t<trk>\r\n"; gpx += "\t<name>" + saveDlg.SafeFileName + "</name>\r\n"; gpx += "\t<trkseg>\r\n"; foreach (GPSData gps in file.AllGPSData) { gpx += "\t\t<trkpt lat=\"" + gps.Latitude.ToString(CultureInfo.InvariantCulture) + "\" " + "lon=\"" + gps.Longitude.ToString(CultureInfo.InvariantCulture) + "\">" + "<time>" + String.Format("{0:s}", gps.DateTime) + "</time>" + "<speed>" + gps.Speed.ToString(CultureInfo.InvariantCulture) + "</speed></trkpt>\r\n"; } gpx += "\t</trkseg>\r\n"; gpx += "\t</trk>\r\n"; gpx += "</gpx>\n"; // Write to GPX file try { // Delete the file if it exists. if (File.Exists(saveDlg.FileName)) { File.Delete(saveDlg.FileName); } // Create the file. using (FileStream fs = File.Create(saveDlg.FileName)) { Byte[] info = new UTF8Encoding(true).GetBytes(gpx); // Add some information to the file. fs.Write(info, 0, info.Length); } // DEBUG: Completed Message Log.WriteLine("Info", "GPX file (" + saveDlg.FileName + ") created!"); // Show complete message MetroWindow w = (MetroWindow)Application.Current.MainWindow; await w.ShowMessageAsync("File Extracted", "GPS data was extracted from " + Path.GetFileName(fileWithPath).ToString() + ". \r\n\r\n" + "The GPX file was saved as: \r\n\t" + saveDlg.FileName); } catch (Exception ex) { Log.WriteLine("ERROR", "Unable to create GPX file: " + saveDlg.FileName); MessageBox.Show(ex.ToString()); } } }
private async void OrganisationWorker_DoWork(object sender, DoWorkEventArgs e) { // Force this thread to work in EN Culture Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en"); // Sort the list of _Clips by StartTime _clips = _clips.OrderBy(o => o.StartTime).ToList(); // Organise previous/next clips foreach (NovatekFile A in _clips) { // Find the file directly before this one if (string.IsNullOrEmpty(A.NextFile)) { foreach (NovatekFile B in _clips) { if (A.FileName != B.FileName && string.IsNullOrEmpty(A.NextFile)) { TimeSpan diff = B.StartTime - A.EndTime; // Anywhere between a -5 seconds and 5 minutes gap between the files if (diff.TotalSeconds >= -5 && diff.TotalSeconds <= 300) { A.NextFile = B.FileName; B.PreviousFile = A.FileName; } } } } // Find the file directly after this one if (string.IsNullOrEmpty(A.PreviousFile)) { foreach (NovatekFile C in _clips) { if (A.FileName != C.FileName && string.IsNullOrEmpty(A.PreviousFile)) { TimeSpan diff = A.StartTime - C.EndTime; // Anywhere between a -5 seconds and 5 minutes gap between the files if (diff.TotalSeconds >= -5 && diff.TotalSeconds <= 300) { A.PreviousFile = C.FileName; C.NextFile = A.FileName; } } } } } // Organise Journeys foreach (NovatekFile D in _clips) { // If this is a starting file, create a new journey if (string.IsNullOrEmpty(D.PreviousFile)) { Journey j = new Journey(); if (D.ValidGPS && D.GPSData != null) { // Retrieve the start town await D.SetStartTown(); j.StartTime = D.StartTime; j.StartTown = D.StartTown; j.Distance = D.Distance; j._clips.Add(D); foreach (GPSData gps in D.GPSData) { j.GPSLocationsFiltered.Add(new Location(gps.Latitude, gps.Longitude)); } foreach (GPSData gps in D.AllGPSData) { j.GPSData.Add(gps); j.GPSLocations.Add(new Location(gps.Latitude, gps.Longitude)); } if (string.IsNullOrEmpty(D.NextFile)) { // Retrieve the end town await D.SetEndTown(); if (D.ValidGPS) { j.EndTown = D.EndTown; } j.EndTime = D.EndTime; } } await Application.Current.Dispatcher.BeginInvoke(new Action(() => _journeyList.Add(j))); } else { NovatekFile c = _clips.Where(x => x.FileName == D.PreviousFile).FirstOrDefault(); // Otherwise find the journey containing the previous file and add this to it foreach (Journey j in _journeyList) { if (j.Clips.Contains(c)) { j.Distance = (j.Distance + D.Distance); j._clips.Add(D); foreach (GPSData gps in D.GPSData) { j.GPSLocationsFiltered.Add(new Location(gps.Latitude, gps.Longitude)); } foreach (GPSData gps in D.AllGPSData) { j.GPSData.Add(gps); j.GPSLocations.Add(new Location(gps.Latitude, gps.Longitude)); } if (string.IsNullOrEmpty(D.NextFile)) { // Retrieve the end town await D.SetEndTown(); if (D.ValidGPS) { j.EndTown = D.EndTown; } j.EndTime = D.EndTime; } } } } } }