473,320 Members | 1,859 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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

Feb 8 '08 #1
1 3131
"William Johnston" <wi******@tenbase2.comwrote:
>
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

Feb 11 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: MLH | last post by:
The A97 set of controls has one at the end entitled "More Controls". Clicking it produces a host of ActiveX and OCX controls that can be dropped onto a form just as easily as a textbox. One of...
0
by: DotNetMania | last post by:
hi.. i have some questions about media player article on codeproject website...... http://www.codeproject.com/cs/media/directshowmediaplayer.asp?df=100&forumid=4399&select=820191#xx793428xx ...
6
by: Sjaakie Helderhorst | last post by:
Hi, I've been fooling around (noob) with VB.NET and put together a remote-controlled Mediaplayer-based 'server'. Had some troubles configuring interop on Windows XP with VS.NET 2003, but...
2
by: Dick | last post by:
Hello, I've written a program that uses the Windows Mediaplayer. There are 2 files generated in my Bin folder: AxInterop.WMPLib.dll Interop.WMPLib.dll When running in the vb.net ide it...
0
by: Nonee | last post by:
Hello- I have a form with the mediaplayer referenced to play mp3's and avi's and I believe that is what is causing the problem. I am not sure, but I am hoping. Anyway, I "published" the vb.net...
3
by: MikeY | last post by:
From my understanding when exporting your app.exe with a mediaplay hooked up, you must also place a copy of AxInterop.WMPLib.dll and Interop.WMPLib.dll" wrapper class. to the location of my...
7
by: xhunter | last post by:
ok here is my problem, I am trying to change the source file of the mediplayer using javascript, my script works perfectly in "Internet Explorer", but no matter what I do, it doesn't work in...
3
by: William Johnston | last post by:
Hello, How do I explictly destruct a MediaPlayer object? The compiler complained about overriding Finalize. MediaPlayer does not implement IDisposable. Any suggestions? Thanks,
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.