[longomatch] Try to get the stream duration from 2 different ways



commit 9c37fd860d79bf7890bb6625f1cbb39e8b4b722a
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Fri Apr 9 22:52:40 2010 +0200

    Try to get the stream duration from 2 different ways
    
    On windows some formats reports sometimes a 0 duration.
    Trying to get it from 2 different places we reduce the error rate

 CesarPlayer/Player/GstPlayer.cs       |    2 +-
 CesarPlayer/Utils/PreviewMediaFile.cs |    8 +++++---
 2 files changed, 6 insertions(+), 4 deletions(-)
---
diff --git a/CesarPlayer/Player/GstPlayer.cs b/CesarPlayer/Player/GstPlayer.cs
index 819064e..106f469 100644
--- a/CesarPlayer/Player/GstPlayer.cs
+++ b/CesarPlayer/Player/GstPlayer.cs
@@ -758,7 +758,7 @@ namespace LongoMatch.Video.Player {
 		[DllImport("libcesarplayer.dll")]
 		static extern IntPtr bacon_video_widget_get_backend_name(IntPtr raw);
 
-		public string BackendName { 
+		public string BackendName {
 			get {
 				IntPtr raw_ret = bacon_video_widget_get_backend_name(Handle);
 				string ret = GLib.Marshaller.PtrToStringGFree(raw_ret);
diff --git a/CesarPlayer/Utils/PreviewMediaFile.cs b/CesarPlayer/Utils/PreviewMediaFile.cs
index ba56f13..3b46b01 100644
--- a/CesarPlayer/Utils/PreviewMediaFile.cs
+++ b/CesarPlayer/Utils/PreviewMediaFile.cs
@@ -66,7 +66,7 @@ namespace LongoMatch.Video.Utils
 		}
 		
 		public new static PreviewMediaFile GetMediaFile(string filePath){
-			int duration;			
+			int duration=0;			
 			bool hasVideo;
 			bool hasAudio;
 			string audioCodec = "";
@@ -82,8 +82,7 @@ namespace LongoMatch.Video.Utils
 			try{
 				factory =  new MultimediaFactory();
 				reader = factory.getMetadataReader();
-				reader.Open(filePath);
-				duration = (int)reader.GetMetadata(GstMetadataType.Duration);						
+				reader.Open(filePath);				
 				hasVideo = (bool) reader.GetMetadata(GstMetadataType.HasVideo);
 				hasAudio = (bool) reader.GetMetadata(GstMetadataType.HasAudio);
 				if (hasAudio){
@@ -96,6 +95,9 @@ namespace LongoMatch.Video.Utils
 					thumbnailer.Open(filePath);
 					thumbnailer.SeekTime(1000,false);
 					preview = thumbnailer.GetCurrentFrame(THUMBNAIL_MAX_WIDTH,THUMBNAIL_MAX_HEIGHT);
+					duration = (int)(thumbnailer as GstPlayer).StreamLength;				/* On Windows some formats report a 0 duration, try a last time with the reader */
+					if (duration == 0)
+						duration = (int)reader.GetMetadata(GstMetadataType.Duration);
 					thumbnailer.Dispose();
 				}			
 				height = (int) reader.GetMetadata(GstMetadataType.DimensionY);



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