From: SC on
Hi,

I'm also facing the same problem. Did you get an answer for this??



William Johnston wrote:

Re: MediaPlayer coding question
11-Feb-08

"William Johnston" <williamj(a)tenbase2.com> wrote:

Still getting black thumbnails after setting BeginTime for MediaTimeLine object.

Here is my modifed thumbnail creator code:

private void CreateThumbnail(string file, string outputDir)
{
try
{
MediaPlayer mp = new MediaPlayer();

MediaTimeline mt = new MediaTimeline(new Uri(file));
mt.BeginTime = new TimeSpan(00, 00, 02);
MediaClock mc = mt.CreateClock();

string beginTime = null;

if (debug)
{
beginTime = mc.Timeline.BeginTime.ToString();
System.Console.WriteLine("beginTime: [" + beginTime + "]");
}

mp.Clock = mt.CreateClock();

if (debug)
{
beginTime = mp.Clock.Timeline.BeginTime.ToString();
System.Console.WriteLine("beginTime: [" + beginTime + "]");
}

RenderTargetBitmap rtb = new RenderTargetBitmap(130, 92, 1 / 200, 1 / 200, PixelFormats.Pbgra32);
DrawingVisual dv = new DrawingVisual();
DrawingContext dc = dv.RenderOpen();
RectAnimation ra = new RectAnimation();
dc.DrawVideo(mp, new Rect(0, 0, 130, 92));

dc.Close();
rtb.Render(dv);

string filename = GetFileName(file);

//create the output filename
object[] formatParams = new object[2];
formatParams[0] = outputDir;
formatParams[1] = filename;

string outputFileName = null;

outputFileName = string.Format("{0}\\tn_{1}.bmp", formatParams);

BmpBitmapEncoder encoder = new BmpBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(rtb));

using (FileStream writer = new FileStream(outputFileName, FileMode.Create))
{
System.Console.WriteLine("Saving [{0}]", outputFileName);
encoder.Save(writer);
}
}
catch (Exception e)
{
System.Console.WriteLine("CreateThumbnail: " + e.Message);
System.Environment.Exit(1);
}
}

Thanks,
William Johnston

Previous Posts In This Thread:

On Friday, February 08, 2008 2:33 PM
William Johnston wrote:

MediaPlayer coding question
Hi,

I modified a thumbnail creation app and get black images since the first second is black as well.

My questions are:

1. How do I set the MediaPlayer.Clock property to start screen capture at two seconds?
2. How do I open a file without using a URI?

Here's the sample code:

private void CreateThumbnail(string file, string outputDir)
{
try
{

Uri uri = new Uri(file);

MediaPlayer mp = new MediaPlayer();
mp.Open(uri);
//mp.Position = new TimeSpan(00, 00, 02);
mp.Clock = new MediaTimeline(new TimeSpan(00, 00, 02)).CreateClock();
RenderTargetBitmap rtb = new RenderTargetBitmap(320, 240, 1 / 200, 1 / 200, PixelFormats.Pbgra32);
DrawingVisual dv = new DrawingVisual();
DrawingContext dc = dv.RenderOpen();
// RectAnimation ra = new RectAnimation();
// ra.BeginTime = new TimeSpan(00, 00, 02);
// dc.DrawVideo(mp, new Rect(0, 0, 320, 240), ra.CreateClock());
dc.DrawVideo(mp, new Rect(0, 0, 320, 240));

dc.Close();
rtb.Render(dv);
//Image im = new Image();
//im.Source = BitmapFrame.Create(rtb);

string filename = GetFileName(file);

//create the output filename
object[] formatParams = new object[2];
formatParams[0] = outputDir;
formatParams[1] = filename;

string outputFileName = null;

outputFileName = string.Format("{0}\\tn_{1}.bmp", formatParams);

BmpBitmapEncoder encoder = new BmpBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(rtb));

using (FileStream writer = new FileStream(outputFileName, FileMode.Create))
{
System.Console.WriteLine("Saving [{0}]", outputFileName);
encoder.Save(writer);
}
}
catch (Exception e)
{
System.Console.WriteLine("CreateThumbnail: " + e.Message);
System.Environment.Exit(1);
}
}

Any suggestions?

Thanks,
William Johnston

On Monday, February 11, 2008 10:16 AM
William Johnston wrote:

Re: MediaPlayer coding question
"William Johnston" <williamj(a)tenbase2.com> wrote:

Still getting black thumbnails after setting BeginTime for MediaTimeLine object.

Here is my modifed thumbnail creator code:

private void CreateThumbnail(string file, string outputDir)
{
try
{
MediaPlayer mp = new MediaPlayer();

MediaTimeline mt = new MediaTimeline(new Uri(file));
mt.BeginTime = new TimeSpan(00, 00, 02);
MediaClock mc = mt.CreateClock();

string beginTime = null;

if (debug)
{
beginTime = mc.Timeline.BeginTime.ToString();
System.Console.WriteLine("beginTime: [" + beginTime + "]");
}

mp.Clock = mt.CreateClock();

if (debug)
{
beginTime = mp.Clock.Timeline.BeginTime.ToString();
System.Console.WriteLine("beginTime: [" + beginTime + "]");
}

RenderTargetBitmap rtb = new RenderTargetBitmap(130, 92, 1 / 200, 1 / 200, PixelFormats.Pbgra32);
DrawingVisual dv = new DrawingVisual();
DrawingContext dc = dv.RenderOpen();
RectAnimation ra = new RectAnimation();
dc.DrawVideo(mp, new Rect(0, 0, 130, 92));

dc.Close();
rtb.Render(dv);

string filename = GetFileName(file);

//create the output filename
object[] formatParams = new object[2];
formatParams[0] = outputDir;
formatParams[1] = filename;

string outputFileName = null;

outputFileName = string.Format("{0}\\tn_{1}.bmp", formatParams);

BmpBitmapEncoder encoder = new BmpBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(rtb));

using (FileStream writer = new FileStream(outputFileName, FileMode.Create))
{
System.Console.WriteLine("Saving [{0}]", outputFileName);
encoder.Save(writer);
}
}
catch (Exception e)
{
System.Console.WriteLine("CreateThumbnail: " + e.Message);
System.Environment.Exit(1);
}
}

Thanks,
William Johnston


Submitted via EggHeadCafe - Software Developer Portal of Choice
WPF GridView Sample To Insert, Update, and Delete Records
http://www.eggheadcafe.com/tutorials/aspnet/fc9a5bf6-f5bb-4443-a92a-c9a46fd3aeb2/wpf-gridview-sample-to-in.aspx