Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / February 2008

Tip: Looking for answers? Try searching our database.

MediaPlayer coding question

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
William Johnston - 08 Feb 2008 19:10 GMT
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
William Johnston - 11 Feb 2008 14:58 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.