473,774 Members | 2,128 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Workaround for MediaPlayer thumbnail app causes infinite loop


Hi,

A support technician proposed a workaround to black images created for thumbnails.

The code to create a thumbnail is below:

//passes results to Response.Output Stream
private void CreateThumbnail (string url)
{
try
{
MediaPlayer mp = new MediaPlayer();
mp.Open(new Uri(url));
mp.Position = new TimeSpan(00, 00, 01);
Workaround(mp);

RenderTargetBit map rtb = new RenderTargetBit map(260, 184, 1 / 200, 1 / 200, PixelFormats.Pb gra32);

DrawingVisual dv = new DrawingVisual() ;
DrawingContext dc = dv.RenderOpen() ;
RectAnimation ra = new RectAnimation() ;
dc.DrawVideo(mp , new Rect(0, 0, 260, 184));

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

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

MemoryStream memoryStream = new MemoryStream();
encoder.Save(me moryStream);

Bitmap bmp = new Bitmap(memorySt ream);
Response.Conten tType = "image/JPEG";
bmp.Save(Respon se.OutputStream , ImageFormat.Jpe g);
}
catch (Exception e)
{
System.Console. WriteLine("Crea teThumbnail: " + e.Message);
System.Environm ent.Exit(1);
}
}

private void Workaround(Medi aPlayer mp)
{
mp.Play();
TimeSpan startPosition = mp.Position;
while (startPosition == mp.Position)
{
System.Threadin g.Thread.Sleep( 1000);
}
mp.Pause();
}

private const string defaultVideoURL = "http://tenbase2.com/movie_clips/Glenn%20Beck%20 11_07_07/VTS_01_1/movie_segment5. mp2";
An infinite loop sometimes occurs for the Workaround while loop. A black thumbnail is created without the while loop.

Any suggestions on how to reliably create a thumbnail?

This app is an HTTP Handler as an ASP.NET Web application.

Thanks,
William Johnston

Jun 27 '08 #1
0 1435

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

Similar topics

43
5602
by: Gremlin | last post by:
If you are not familiar with the halting problem, I will not go into it in detail but it states that it is impossible to write a program that can tell if a loop is infinite or not. This is a fallacy built on the assumption of mythical infinite all powerfull machines. In reality we deal with finite machines that are capable of two states in a loop, they either terminate, or repeat themselves. In the mythical halting problem scenario...
5
4950
by: mailpitches | last post by:
Hello, Is there any way to kill a Javascript infinite loop in Safari without force-quitting the browser? MP
0
1843
by: Cecil Windham | last post by:
I'm enabling users to rotate photos and generate thumbnails. I have discovered that if, after a user rotates a photo 180 degrees, then generates a thumbnail, that the resulting thumbnail appears unrotated (i.e., in original position, or rotated zero degrees). Why is this? (and yes, I have verified that the "original" from which the thumbnail is generated has, in fact, been rotated 180 degrees prior to generating the thumbnail).
1
3349
by: Comcast | last post by:
I understand that one of the limitations of the Image.GetThumbnailImage() function is that it's not really good for creating "large" thumbnails because if it exists in the image file, the function will take the embedded thumbnail and actually blow it up to the requested height/width. Does anyone know if Microsoft will be fixing this "feature" or whether there's a work around to force the function to use the full image to scale? Thanks...
5
3227
by: Allerdyce.John | last post by:
Hi, I have this piece of code which loops thru a STL list, but that causs an infinite loop. bool Executer::group(MyList& bl, ResultList & grl) { for (ExecuterList::iterator i = _executerList.begin(); i != _executerList.end(); i++) {
44
4320
by: James Watt | last post by:
can anyone tell me how to do an infinite loop in C/C++, please ? this is not a homework question .
1
3178
by: William Johnston | last post by:
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:
0
9621
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9914
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8939
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7463
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5355
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5484
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3611
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2852
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.