gnome-subtitles r1084 - in trunk: gstreamer-playbin-0.2.1 src/GnomeSubtitles/Dialog src/GnomeSubtitles/Ui src/GnomeSubtitles/Ui/VideoPreview src/GnomeSubtitles/Ui/VideoPreview/Exception



Author: pcastro
Date: Sun Nov 23 18:40:54 2008
New Revision: 1084
URL: http://svn.gnome.org/viewvc/gnome-subtitles?rev=1084&view=rev

Log:
Major refactoring of the video playback engine:
- Moved Gstreamer-playbin into the Gnome Subtitles source dir
- Gstreamer-playbin no longer builds as a separate package (no separate dll, although the .so lib is still built separately)
- GStreamer events are now received asynchronously
- Loading a video is also asynchronous (playbin instructed to open the file, but video information, duration and Loaded state received asynchronously afterwards). This means the user interface adapts to the video in an asynchronous way.
- No longer has to use tricky scheme to wait for video loading (waiting some seconds for all the video information to be gathered)

Removed:
   trunk/gstreamer-playbin-0.2.1/
   trunk/src/GnomeSubtitles/Dialog/VideoFileOpenErrorDialog.cs
   trunk/src/GnomeSubtitles/Ui/VideoPreview/Exception/
Modified:
   trunk/src/GnomeSubtitles/Dialog/FileOpenErrorDialog.cs
   trunk/src/GnomeSubtitles/Dialog/VideoErrorDialog.cs
   trunk/src/GnomeSubtitles/Dialog/VideoSeekToDialog.cs
   trunk/src/GnomeSubtitles/Ui/MainUi.cs
   trunk/src/GnomeSubtitles/Ui/VideoPreview/Player.cs
   trunk/src/GnomeSubtitles/Ui/VideoPreview/PlayerPositionWatcher.cs
   trunk/src/GnomeSubtitles/Ui/VideoPreview/Video.cs
   trunk/src/GnomeSubtitles/Ui/VideoPreview/VideoPosition.cs

Modified: trunk/src/GnomeSubtitles/Dialog/FileOpenErrorDialog.cs
==============================================================================
--- trunk/src/GnomeSubtitles/Dialog/FileOpenErrorDialog.cs	(original)
+++ trunk/src/GnomeSubtitles/Dialog/FileOpenErrorDialog.cs	Sun Nov 23 18:40:54 2008
@@ -47,20 +47,12 @@
 		actionButton.Image = new Image(Stock.Open, IconSize.Button);
 		dialog.AddButton(Stock.Ok, ResponseType.Ok);
 	}
-
-
-	/* Abstract methods */
-	
-	protected abstract string SecondaryTextFromException (Exception exception);
-
 	
-	/* Private methods */
-	
-	private string GetPrimaryText (string filename) {
+	protected virtual string GetPrimaryText (string filename) {
 		return primaryTextStart + " " + filename + ".";
 	}
 	
-	private string GetSecondaryText (Exception exception) {
+	protected virtual string GetSecondaryText (Exception exception) {
 		string text = SecondaryTextFromException(exception);
 		if (text != String.Empty)
 			return text;
@@ -70,6 +62,11 @@
 			return GetGeneralExceptionErrorMessage(exception);
 	}
 
+
+	/* Abstract methods */
+	
+	protected abstract string SecondaryTextFromException (Exception exception);
+
 }
 
 }

Modified: trunk/src/GnomeSubtitles/Dialog/VideoErrorDialog.cs
==============================================================================
--- trunk/src/GnomeSubtitles/Dialog/VideoErrorDialog.cs	(original)
+++ trunk/src/GnomeSubtitles/Dialog/VideoErrorDialog.cs	Sun Nov 23 18:40:54 2008
@@ -17,17 +17,32 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-using Gtk;
+using GnomeSubtitles.Ui.VideoPreview.Exceptions;
 using Mono.Unix;
 using System;
 
 namespace GnomeSubtitles.Dialog {
 
-public class VideoErrorDialog : BasicErrorDialog {
-	private static string primary = Catalog.GetString("Could not continue the video playback");
-	private static string secondaryInitial = Catalog.GetString("The following error has occurred: ");
+public class VideoErrorDialog : FileOpenErrorDialog {
+
+	/* Strings */
+	private string primaryTextStart = Catalog.GetString("Could not play the file");
+
+	public VideoErrorDialog (Uri uri, Exception exception) : base(uri, exception) {
+		Console.Error.WriteLine("Video error: " + exception.ToString());
+	}
+
+	/* Overriden members */
+	
+	protected override string GetPrimaryText (string filename) {
+		return primaryTextStart + " " + filename + ".";
+	}
 	
-	public VideoErrorDialog (string secondary) : base(primary, secondaryInitial + secondary) {
+	protected override string SecondaryTextFromException (Exception exception) {
+		if (exception is PlayerEngineException)
+			return (exception as PlayerEngineException).Error;
+		else
+			return String.Empty;
 	}
 
 }

Modified: trunk/src/GnomeSubtitles/Dialog/VideoSeekToDialog.cs
==============================================================================
--- trunk/src/GnomeSubtitles/Dialog/VideoSeekToDialog.cs	(original)
+++ trunk/src/GnomeSubtitles/Dialog/VideoSeekToDialog.cs	Sun Nov 23 18:40:54 2008
@@ -52,12 +52,12 @@
 		
 		if (timingMode == TimingMode.Times) {
 			Core.Util.SetSpinButtonTimingMode(spinButton, Base.TimingMode);
-			Core.Util.SetSpinButtonAdjustment(spinButton, Base.Ui.Video.Position.Length, false);
+			Core.Util.SetSpinButtonAdjustment(spinButton, Base.Ui.Video.Position.Duration, false);
 			SetSpinButtonValue(Base.Ui.Video.Position.CurrentTime.TotalMilliseconds);
 		}
 		else {
 			Core.Util.SetSpinButtonTimingMode(spinButton, Base.TimingMode);
-			Core.Util.SetSpinButtonAdjustment(spinButton, Base.Ui.Video.Position.LengthInFrames, false);
+			Core.Util.SetSpinButtonAdjustment(spinButton, Base.Ui.Video.Position.DurationInFrames, false);
 			SetSpinButtonValue(Base.Ui.Video.Position.CurrentFrames);
 			
 			positionLabel.TextWithMnemonic = Catalog.GetString("Seek to _frame:");

Modified: trunk/src/GnomeSubtitles/Ui/MainUi.cs
==============================================================================
--- trunk/src/GnomeSubtitles/Ui/MainUi.cs	(original)
+++ trunk/src/GnomeSubtitles/Ui/MainUi.cs	Sun Nov 23 18:40:54 2008
@@ -366,19 +366,9 @@
     private void OpenVideo (string videoUriString) {
     	Menus.SetViewVideoActivity(true);
     	Uri videoUri = null;
-		try {
-			videoUri = new Uri(videoUriString);
-			Video.Open(videoUri);
-			UpdateFromOpenVideo();
-		}
-		catch (Exception exception) {
-			Video.Close();
-			VideoFileOpenErrorDialog errorDialog = new VideoFileOpenErrorDialog(videoUri, exception);
-			errorDialog.Show();
-			bool toOpenAgain = errorDialog.WaitForResponse();
-	    	if (toOpenAgain)
-	    		OpenVideo();
-		}
+
+		videoUri = new Uri(videoUriString);
+		Video.Open(videoUri);
     }
     
     private void Save (FileProperties fileProperties) {

Modified: trunk/src/GnomeSubtitles/Ui/VideoPreview/Player.cs
==============================================================================
--- trunk/src/GnomeSubtitles/Ui/VideoPreview/Player.cs	(original)
+++ trunk/src/GnomeSubtitles/Ui/VideoPreview/Player.cs	Sun Nov 23 18:40:54 2008
@@ -17,7 +17,7 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-using GnomeSubtitles.Ui.VideoPreview.Exception;
+using GnomeSubtitles.Ui.VideoPreview.Exceptions;
 using GStreamer;
 using Gtk;
 using System;
@@ -25,98 +25,84 @@
 namespace GnomeSubtitles.Ui.VideoPreview {
 
 /* Delegates */
-public delegate void PlayerErrorCaughtFunc (string message); //Represents a function that handles a caught error
+public delegate void PlayerErrorEventHandler (Uri videoUri, Exception e);
+public delegate void VideoDurationEventHandler (TimeSpan duration);
 
 public class Player {
+	private AspectFrame frame = null;
 	private Socket socket = null;
 	private Playbin playbin = null;
 	private PlayerPositionWatcher position = null;
-	private bool playbinLoadError= false; //used to indicate whether an error has occured while loading the playbin
+	private bool hasFoundDuration = false;
+	private Uri videoUri = null;
 
-	/* Delegate functions */
-	private EventHandler EndReached;
-	private PlayerErrorCaughtFunc ErrorCaught;
+	public Player (AspectFrame aspectFrame) {
+		this.frame = aspectFrame;
 
-	public Player () {
-		CreateSocket();
-		position = new PlayerPositionWatcher(GetPosition);
-	}
-
-	public Socket Widget {
-		get { return socket; }
-	}
-	
-	public bool IsLoaded {
-		get { return playbin != null; }
+		InitializeSocket();
+		InitializePositionWatcher();
+		InitializePlaybin();
 	}
 	
-	public void Open (Uri videoUri) {
-		Playbin newPlaybin = new Playbin();
-	
-		/* Initialize the playbin */
-		if (!newPlaybin.Initiate(socket.Id))
-			throw new PlayerCouldNotOpenVideoException();
+	private void InitializePlaybin () {
+		playbin = new Playbin();
 		
-		/* Handle errors during playbin loading */
-		newPlaybin.EventChanged += OnPlaybinLoadEventChanged;
+		if (!playbin.Initiate(socket.Id))
+			throw new PlayerCouldNotInitiateEngineException();
 		
-		/* Load the playbin */
-		newPlaybin.Load(videoUri.AbsoluteUri);
-		
-		/* Wait for the playbin to be ready (have video information) */
-		bool isReady = WaitForPlaybinReady(newPlaybin);
-		
-		newPlaybin.EventChanged -= OnPlaybinLoadEventChanged;
-		playbinLoadError = false;
-		if (!isReady) {
-			/* An error has occurred, returning */
-			throw new PlayerCouldNotOpenVideoException();
-		}
-		
-		this.playbin = newPlaybin;
-
-		/* Load was successful, connecting the normal handlers */
-		this.playbin.StateChanged += OnStateChanged;
-		this.playbin.EventChanged += OnEventChanged;
-		
-		/* Start position watcher */
-		position.Start();
-	}
-	
-	public void Close () {
-		if (playbin != null) {
-			playbin.StateChanged -= OnStateChanged;
-			playbin.EventChanged -= OnEventChanged;
-			DestroyPlaybin();
-			
-			position.Stop();
-		}
+		playbin.Error += OnPlaybinError;
+		playbin.EndOfStream += OnPlaybinEndOfStream;
+		playbin.StateChanged += OnPlaybinStateChanged;
+		playbin.FoundVideoInfo += OnPlaybinFoundVideoInfo;
+		playbin.FoundTag += OnPlaybinFoundTag;
 	}
 	
-	public PlayerTimeChangedFunc OnPositionChanged {
-		set { position.OnPlayerPositionChanged = value; }
+	private void InitializePositionWatcher () {
+		position = new PlayerPositionWatcher(GetPosition);
+		position.Changed += OnPositionWatcherChanged;		
 	}
 	
-	public PlayerErrorCaughtFunc OnErrorCaught {
-		set { this.ErrorCaught = value; }
-	}
+	/* Events */
+	public event PlayerErrorEventHandler Error;
+	public event EndOfStreamEventHandler EndOfStream;
+	public event StateEventHandler StateChanged;
+	public event PositionChangedEventHandler PositionChanged;
+	public event VideoInfoEventHandler FoundVideoInfo;
+	public event VideoDurationEventHandler FoundDuration;
 	
-	public EventHandler OnEndReached {
-		set { this.EndReached = value; }
+
+	/* Properties */
+
+	public TimeSpan Duration {
+		get { return playbin.Duration; }
 	}
 	
 	public float AspectRatio {
 		get { return playbin.VideoInfo.AspectRatio; }
 	}
 	
-	public TimeSpan Length {
-		get { return playbin.Duration; }
-	}
-	
 	public float FrameRate {
 		get { return playbin.VideoInfo.FrameRate; }
 	}
+
+
+	/* Public methods */
+	
+	public void Open (Uri videoUri) {
+		this.videoUri = videoUri;
+	
+		/* Load the playbin */
+		playbin.Load(videoUri.AbsoluteUri);
+	}
 	
+	public void Close () {
+		position.Stop();
+		playbin.Unload();
+
+		videoUri = null;
+		hasFoundDuration = false;
+	}
+
 	public void Play () {
 		playbin.Play();
 	}
@@ -137,106 +123,85 @@
 		playbin.Seek(newPosition);
 	}
 	
-	// newPosition in milliseconds
 	public void Seek (double newPosition) {
-		playbin.Seek(newPosition);
+		playbin.Seek(newPosition); // newPosition in milliseconds
+	}
+	
+	public void Dispose () {
+		Close();
+		playbin.Dispose();
 	}
 
+
 	/* Private members */
 	
-	private void CreateSocket () {
+	private void InitializeSocket () {
 		socket = new Socket();
-		socket.ModifyBg(StateType.Normal, socket.Style.Black);	
-	}
+		socket.ModifyBg(StateType.Normal, socket.Style.Black);
 
-	private void DestroyPlaybin () {
-		playbinLoadError = false;
-		playbin.Dispose();
-		playbin = null;
-	}
-	
-	/// <summary>Waits for the playbin to be ready.</summary>
-	/// <param name="newPlaybin">The playbin to wait for.</param>
-	/// <remarks>The playbin is ready when it is able to access both the duration and video information.</remarks>
-	/// <returns>Whether the playbin is ready.</returns>
-	private bool WaitForPlaybinReady (Playbin newPlaybin) {
-		bool gotVideoInfo = false;
-		bool gotDuration = false;
-
-		DateTime endTime = DateTime.Now.AddSeconds(5); //Total time to wait for either successful load or error
-		while (DateTime.Now < endTime) {
-			if (playbinLoadError)
-				return false;
-		
-			/* Check for duration if it hasn't been accessed yet */
-			if (!gotDuration) {
-				TimeSpan duration = newPlaybin.Duration;
-				if (duration == TimeSpan.Zero) {
-					GLib.MainContext.Iteration(); //Because an error event may be triggered and we have to catch it
-					System.Threading.Thread.Sleep(15); //milliseconds
-					continue;
-				}
-				else {
-					gotDuration = true;
-					Console.Error.WriteLine("Got duration: " + duration);
-				}
-			}
-		
-			/* Check for video information if it hasn't been accessed yet */
-			if (!gotVideoInfo) {
-				EngineVideoInfo info = newPlaybin.VideoInfo;
-				if (info == null) {
-					GLib.MainContext.Iteration(); //Because an error event may be triggered and we have to catch it
-					System.Threading.Thread.Sleep(15); //milliseconds
-					continue;
-				}
-				else {
-					gotVideoInfo = true;
-					
-					Console.Error.WriteLine("Got video info: " + info + " (took " + (DateTime.Now - endTime.AddSeconds(-5)).TotalSeconds + " seconds)");
-				}
-			}
+		frame.Child = socket;
 
-			/* Was able to access all info, returning */
-			return true;
-		}
-		
-		/* Was not able to access any info */
-		return false;
+		socket.Realize();
+		socket.Show();
 	}
 	
 	/// <summary>Gets the current player position.</summary>
 	private TimeSpan GetPosition () {
-		if (playbin == null)
-			return TimeSpan.Zero;
-		else
-			return playbin.CurrentPosition;
+		return playbin.CurrentPosition;
 	}
 
 	
 	/* Event members */
+	
+	private void OnPlaybinError (ErrorEventArgs args) {
+		if (Error != null)
+			Error(videoUri, new PlayerEngineException(args.Error, args.Debug));
+	}
+	
+	private void OnPlaybinEndOfStream () {
+		position.Stop();
+		if (EndOfStream != null)
+			EndOfStream();
+	}
+	
+	private void OnPlaybinStateChanged (StateEventArgs args) {
+		switch (args.State) {
+			case MediaStatus.Playing:
+				position.Start();
+				break;
+			case MediaStatus.Paused:
+				position.Start();
+				break;
+			default:
+				position.Stop();
+				break;
+		}
 
-	private void OnStateChanged (object o, EngineStateArgs args) {
-		if ((args.State == MediaStatus.Playing) || (args.State == MediaStatus.Paused))
-			position.Start();
-		else
-			position.Stop();
+		if (StateChanged != null)
+			StateChanged(args);
 	}
 	
-	private void OnEventChanged (object o, EngineEventArgs args) {
-		if (args.Event == MediaEvents.EndOfStream) {
-			EndReached(this, EventArgs.Empty);		
-		}
-		else if (args.Event == MediaEvents.Error) {
-			ErrorCaught(args.Message);
-		}
+	private void OnPositionWatcherChanged (TimeSpan time) {
+		if (PositionChanged != null)
+			PositionChanged(time);
+	}
+
+	private void OnPlaybinFoundVideoInfo (VideoInfoEventArgs args) {
+		Console.Error.WriteLine("Got video info: " + args.VideoInfo.ToString());
+		frame.Ratio = args.VideoInfo.AspectRatio;
+
+		if (FoundVideoInfo != null)
+			FoundVideoInfo(args);
 	}
 	
-	private void OnPlaybinLoadEventChanged (object o, EngineEventArgs args) {
-		if (args.Event == MediaEvents.Error) {
-			Console.Error.WriteLine("Caught an error while loading the playbin: " + args.Message);
-			playbinLoadError = true;
-		}	
+	private void OnPlaybinFoundTag (TagEventArgs args) {
+		if ((!hasFoundDuration) && (FoundDuration != null) && (playbin.Duration != TimeSpan.Zero)) {
+			TimeSpan duration = playbin.Duration;
+			Console.Error.WriteLine("Got video duration: " + duration);
+			
+			hasFoundDuration = true;
+			FoundDuration(duration);
+		}
 	}
 	
 }

Modified: trunk/src/GnomeSubtitles/Ui/VideoPreview/PlayerPositionWatcher.cs
==============================================================================
--- trunk/src/GnomeSubtitles/Ui/VideoPreview/PlayerPositionWatcher.cs	(original)
+++ trunk/src/GnomeSubtitles/Ui/VideoPreview/PlayerPositionWatcher.cs	Sun Nov 23 18:40:54 2008
@@ -25,14 +25,17 @@
 
 /* Delegates */
 public delegate TimeSpan PlayerGetTimeFunc (); //Represents a function that gets a time from the player
-public delegate void PlayerTimeChangedFunc (TimeSpan position); //Represents a function that handles changes in the position
+public delegate void PositionChangedEventHandler (TimeSpan position); //Represents a function that handles changes in the position
 
 public class PlayerPositionWatcher {
 	private uint timeoutId = 0;
 	
+	/* Events */
+	public event PositionChangedEventHandler Changed;
+	
 	/* Delegate functions */
 	private PlayerGetTimeFunc PlayerGetPosition;
-	private PlayerTimeChangedFunc PlayerPositionChanged;
+
 	
 	/* Constants */
 	private const int timeout = 100; //milliseconds
@@ -41,10 +44,6 @@
 		PlayerGetPosition = playerGetPositionFunc;
 	}
 
-	public PlayerTimeChangedFunc OnPlayerPositionChanged {
-		set { PlayerPositionChanged = value; }
-	}
-
 	
 	/* Public methods */
 	
@@ -78,8 +77,8 @@
 	}
 		
 	private void EmitPositionChanged (TimeSpan position) {
-		if (PlayerPositionChanged != null)
-			PlayerPositionChanged(position);
+		if (Changed != null)
+			Changed(position);
 	}
 
 }

Modified: trunk/src/GnomeSubtitles/Ui/VideoPreview/Video.cs
==============================================================================
--- trunk/src/GnomeSubtitles/Ui/VideoPreview/Video.cs	(original)
+++ trunk/src/GnomeSubtitles/Ui/VideoPreview/Video.cs	Sun Nov 23 18:40:54 2008
@@ -20,6 +20,7 @@
 using GnomeSubtitles.Core;
 using GnomeSubtitles.Dialog;
 using Gtk;
+using GStreamer;
 using SubLib.Core;
 using SubLib.Core.Domain;
 using SubLib.Core.Timing;
@@ -46,32 +47,13 @@
 	public Video () {
 		videoArea = Base.GetWidget(WidgetNames.VideoAreaHBox) as HBox;
 		
-		/* Create the video Frame */
-		frame = new AspectFrame(null, 0.5f, 0.5f, 1.6f, false);
-		frame.Shadow = ShadowType.None;
-		EventBox videoFrameEventBox = new EventBox();
-		videoFrameEventBox.Add(frame);
-		videoFrameEventBox.ModifyBg(StateType.Normal, videoFrameEventBox.Style.Black);
-
-		/* Attach the video frame */
-		Table videoImageTable = Base.GetWidget("videoImageTable") as Table;
-		videoImageTable.Attach(videoFrameEventBox, 0, 1, 0, 1);
-		videoImageTable.ShowAll();
-		
-		/* Set player */
-		player = new Player();
-		player.OnEndReached = OnPlayerEndReached;
-		player.OnErrorCaught = OnPlayerErrorCaught;
+		InitializeVideoFrame();
+		InitializePlayer();
 		
 		position = new VideoPosition(player);
 		subtitle = new VideoSubtitle(position);
-	
-		LoadVideoWidget(player.Widget);
-		
-		/* Set the custom icons */
+
 		SetCustomIcons();
-		
-		/* Connect signals */
 		ConnectPlayPauseButtonSignals();
 	}
 	
@@ -109,24 +91,15 @@
 		Close();
 
 		player.Open(videoUri);
-
-		SetControlsSensitivity(true);
-		position.Enable();
-		frame.Ratio = player.AspectRatio;
-		
-		Core.Base.Ui.Menus.AddFrameRateVideoTag(player.FrameRate);
-		
-		isLoaded = true;
 	}
 	
 	public void Close () {
 		if (!isLoaded)
 			return;
 	
+		System.Console.WriteLine("Closing...");
 		isLoaded = false;
 
-		float oldFrameRate = player.FrameRate; //Need to store this before closing the player
-	
 		player.Close();
 		subtitle.Close();
 		position.Disable();
@@ -139,7 +112,7 @@
 		SilentDisablePlayPauseButton();		
 		SetControlsSensitivity(false);
 
-		Core.Base.Ui.Menus.RemoveFrameRateVideoTag(oldFrameRate);
+		Core.Base.Ui.Menus.RemoveFrameRateVideoTag();
 	}
 
 	public void UpdateFromTimingMode (TimingMode newMode) {
@@ -204,12 +177,6 @@
 		player.Pause();
 	}
 
-	private void LoadVideoWidget (Widget widget) {
-		frame.Child = widget;
-		widget.Realize();
-		widget.Show();
-	}
-
 	private void SetCustomIcons () {
 		/* Set the icon for the SetSubtitleStart button */
 		Gdk.Pixbuf pixbuf = new Gdk.Pixbuf(null, videoSetSubtitleStartIconFilename);
@@ -221,6 +188,31 @@
 		image = Base.GetWidget(WidgetNames.VideoSetSubtitleEndButtonImage) as Image;
 		image.FromPixbuf = pixbuf;
 	}
+	
+	private void InitializeVideoFrame () {
+		/* Create frame */
+		frame = new AspectFrame(null, 0.5f, 0.5f, 1.6f, false);
+		frame.Shadow = ShadowType.None;
+		
+		/* Create event box */
+		EventBox videoFrameEventBox = new EventBox();
+		videoFrameEventBox.Add(frame);
+		videoFrameEventBox.ModifyBg(StateType.Normal, videoFrameEventBox.Style.Black);
+	
+		/* Attach event box */
+		Table videoImageTable = Base.GetWidget("videoImageTable") as Table;
+		videoImageTable.Attach(videoFrameEventBox, 0, 1, 0, 1);
+		videoImageTable.ShowAll();
+	}
+	
+	private void InitializePlayer () {
+		player = new Player(frame);
+		
+		player.FoundVideoInfo += OnPlayerFoundVideoInfo;
+		player.StateChanged += OnPlayerStateChanged;
+		player.EndOfStream += OnPlayerEndOfStream;
+		player.Error += OnPlayerError;
+	}
 
 	private void SetControlsSensitivity (bool sensitivity) {
 		Base.GetWidget(WidgetNames.VideoTimingsVBox).Sensitive = sensitivity;
@@ -264,16 +256,30 @@
 			Pause();
 	}
 	
-	private void OnPlayerEndReached (object o, EventArgs args) {
+	private void OnPlayerFoundVideoInfo (VideoInfoEventArgs args) {
+		Core.Base.Ui.Menus.AddFrameRateVideoTag(player.FrameRate);
+	}
+	
+	private void OnPlayerStateChanged (StateEventArgs args) {
+		if (args.State == MediaStatus.Loaded) {
+			SetControlsSensitivity(true);
+			position.Enable();
+			isLoaded = true;
+			Base.Ui.UpdateFromOpenVideo();
+		}
+	}
+	
+	private void OnPlayerEndOfStream () {
 		ToggleButton playPauseButton = Base.GetWidget(WidgetNames.VideoPlayPauseButton) as ToggleButton;
 		playPauseButton.Active = false;
 	}
 	
-	private void OnPlayerErrorCaught (string message) {
-		Console.Error.WriteLine("Caught player error: " + message);
+	private void OnPlayerError (Uri videoUri, Exception e) {
 		Close();
-		VideoErrorDialog dialog = new VideoErrorDialog(message);
-		dialog.WaitForResponse();
+		VideoErrorDialog dialog = new VideoErrorDialog(videoUri, e);
+		bool toOpenAnother = dialog.WaitForResponse();
+		if (toOpenAnother)
+			Base.Ui.OpenVideo();
 	}
 
 }

Modified: trunk/src/GnomeSubtitles/Ui/VideoPreview/VideoPosition.cs
==============================================================================
--- trunk/src/GnomeSubtitles/Ui/VideoPreview/VideoPosition.cs	(original)
+++ trunk/src/GnomeSubtitles/Ui/VideoPreview/VideoPosition.cs	Sun Nov 23 18:40:54 2008
@@ -18,6 +18,7 @@
  */
 
 using GnomeSubtitles.Core;
+using GStreamer;
 using Gtk;
 using Mono.Unix;
 using SubLib.Core;
@@ -56,7 +57,8 @@
 		lengthValueLabel = Base.GetWidget(WidgetNames.VideoLengthValueLabel) as Label;
 
 		this.player = player;
-		player.OnPositionChanged = OnPlayerPositionChanged;
+		player.PositionChanged += OnPlayerPositionChanged;
+		player.FoundDuration += OnPlayerFoundDuration;
 	}
 
 	/* Public properties */
@@ -74,12 +76,12 @@
 		get { return Convert.ToInt32(SyncUtil.TimeToFrames(position, player.FrameRate)); }
 	}
 	
-	public TimeSpan Length {
-		get { return player.Length; }
+	public TimeSpan Duration {
+		get { return player.Duration; }
 	}
 	
-	public int LengthInFrames {
-		get { return Convert.ToInt32(SyncUtil.TimeToFrames(player.Length, player.FrameRate)); }
+	public int DurationInFrames {
+		get { return Convert.ToInt32(SyncUtil.TimeToFrames(player.Duration, player.FrameRate)); }
 	}
 	
 	/* Public methods */
@@ -95,17 +97,15 @@
 		slider.Sensitive = false;	
 	}
 	
+	//TODO delete
 	public void Enable () {
-		SetLength(player.Length);
-		// TODO DELETE SetSliderLength(TimeSpan.FromMinutes(5)); //Setting the length to a somewhat random number, because we don't know the video length yet TODO
-		slider.Sensitive = true;
-		ConnectSliderSignals();
+		
 	}
 	
 	public void ToggleTimingMode (TimingMode newMode) {
 		UpdatePositionLabel(newMode);
 		UpdatePositionValueLabel(position);
-		TimeSpan length = (player.IsLoaded ? player.Length : TimeSpan.Zero);
+		TimeSpan length = player.Duration;
 		UpdateLengthLabel(newMode, length);
 	}
 
@@ -131,6 +131,12 @@
 		EmitVideoPositionChanged(newPosition);
 	}
 	
+	private void OnPlayerFoundDuration (TimeSpan duration) {
+		SetLength(duration);
+		slider.Sensitive = true;
+		ConnectSliderSignals();
+	}
+	
 	private bool UpdatePlayerPosition () {
 		userUpdateTimeoutId = 0;
 		player.Seek(slider.Value);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]