RSS Search

News  Feeds  Tags  Search Shortcuts

FeedsFarm.com > Non-Destructive Media Edits

Non-Destructive Media Edits

13th Nov 2006, 20:25 GMT

This sample allows you to mark out the offensive sections of your media and skip or mute the sections automatically during playback without modifying the actual media file. Uses Windows Media Player 10 SDK. Arian Kulp Arian Kulp's Blog Difficulty: Intermediate Time Required: 1-3 hours Cost: Free Software: Visual Basic or Visual C# Express Editions, Windows Media Player 10 SDK Hardware: Download: C# Download VB Download For this column, I decided to implement something I've seen a need for before, but never taken the next step to actually create. If you have audio and video files on your computer (and who doesn't these days!), perhaps there are sections of those files that you don't care for as much. It could be commercials in a Windows XP Media Center Edition recorded TV file, or explicit lyrics in a song. For some files you can edit the files in a program such as Windows Movie Maker or various audio editing utilities, but then you would need to either keep two copies of the file, or overwrite the original. You are also limited by what you can modify with DRM-protected formats, or files which are just too big to edit effectively. Wouldn't it be great if you could just mark out the offensive sections of your media and skip or mute the sections automatically during playback without modifying the actual media file? I thought so! This article requires Visual C# 2005 Express Edition or Visual Basic 2005 Express Edition. You can find the Express Edition downloads at http://lab.msdn.microsoft.com/express/. You can also install the Windows Media Player 10 SDK for samples and help files, though this isn't a requirement. Code downloads for this article are available in both C# and Visual Basic. To simplify the code, I started with the .NET sample included with the Media Player 10 SDK. If you choose to install the SDK, you can find the original code at C:\WMSDK\WMPSDK10\samples\dotNet\csharp (assuming you install in the default location). This application demonstrates interacting with the Windows Media Player media library, standard play/pause/stop/forward/reverse buttons, seeking within a file, and embedding a viewer control in a managed form. Most of the original code is intact with only small changes, with the rest of the code added on in new methods. Figure 1: Original user interface I decided that the easiest way to structure the user interface was to allow the user to mark sections of the media during viewing. The start of a section is marked as A, with the end of the section being B. The section within these marks is then either muted or skipped based on an action indicator. The sample covered many basic Windows Media playback needs, so turned out to be a great starting point. The next step was to add the ability to capture the time codes for the A and B marks, and a drop-down box to indicate the action to take. Finally, the marks can be added to a list, with basic add and remove capabilities. As the media plays, the current position is evaluated against the list of marks. If the current position is found to be within a pair of marks, the position is either advanced to skip, or the sound is muted to the next mark. This provides a very seamless viewing experience, and depending on the source media, may not even be noticeable. New marks can be added or removed even during playback, and individual marks can be set active or inactive without needing to remove them from the list. All marks are saved to disk at the same location as the original file ({filename}.marks) and loaded automatically when the media is subsequently loaded. Diagram 2: The improved user interface with marking controls How it Works Windows Media Player has a rich object and event model, making it easy to tie into what it is doing at any time. Using the OpenStateChange event, you can detect media events such as media connecting, media waiting, playlist changed, and other event related to opening and changing streams. The PlayStateChange event lets you know events such as player is ready, playing, reconnecting, scanning, or stopped. The Player object contains a property, currentPosition, representing the number of seconds into the media. If the user clicks the Mark A or Mark B button, the current position is saved to the corresponding label in the UI. The Action drop-down box can then be used to skip or mute the corresponding section, and the mark can be added to the list. Each change to marks results in a save. To indicate the current position in the file using a slider, a timer is triggered every 250ms. When the timer fires, the current position is retrieved from the player control, compared against the media duration, and a new position for the slider is set. This turns out to also be a good place to evaluate the list of marks to see if the media has played to a marked section. This is checked in the EvaluateMarks() section. Visual C# private void EvaluateMarks() { if (Player.playState == WMPPlayState.wmppsPlaying || Player.playState == WMPPlayState.wmppsScanForward || Player.playState == WMPPlayState.wmppsScanReverse) { double pos = Player.Ctlcontrols.currentPosition; bool inMark = false; foreach (MediaMarkListViewItem mark in lvMarks.Items) { if (mark.Active && (pos >= mark.MarkA && pos = mark.MarkA) _ AndAlso (pos

View full story at blogs.msdn.com

Non-Destructive Media Edits related news:

Latest news from Coding4Fun's WebLog: