Bug in Local File

Aug 5, 2010 at 5:18 PM

Hi, I have been developing an application using SMF to play offline content in a OOB Application, and found out the following issue, when I add a item to the Playlist it creates a ProgressiveMediaPlugin and load the file into a FileStream, then when I clear the Playlist and in any point of the application I add the same item again it throws me an IOException with the message "The process cannot access the file 'filename.wmv' because it is being used by another process.", the fix is fairly simple, in the setter of the Source property you should do the following:

// Add this field
private Stream fileStream;

public Uri Source
            if (this._mediaElement == null)
                return null;
            return (this._localSource ?? this._mediaElement.Source);
            if ((Application.Current.IsRunningOutOfBrowser && (value != null)) && value.Scheme.Equals("file", StringComparison.InvariantCultureIgnoreCase))
                this._localSource = value;
                //Instead of 
                //Stream fileStream = this.GetLocalFileStream(value);
                //Do this
                fileStream = this.GetLocalFileStream(value);
                this._localSource = null;
                this._mediaElement.IfNotNull<MediaElement>(delegate (MediaElement i) {
                    i.Source = value;

Then in the method DestroyProgressiveMediaElement do the following

		private void DestroyProgressiveMediaElement()
        if (this._mediaElement != null)
            this._mediaElement.MediaOpened -= new RoutedEventHandler(this.MediaElement_MediaOpened);
            this._mediaElement.MediaFailed -= new EventHandler<ExceptionRoutedEventArgs>(this.MediaElement_MediaFailed);
            this._mediaElement.MediaEnded -= new RoutedEventHandler(this.MediaElement_MediaEnded);
            this._mediaElement.CurrentStateChanged -= new RoutedEventHandler(this.MediaElement_CurrentStateChanged);
            this._mediaElement.MarkerReached -= new TimelineMarkerRoutedEventHandler(this.MediaElement_MarkerReached);
            this._mediaElement.BufferingProgressChanged -= new RoutedEventHandler(this.MediaElement_BufferingProgressChanged);
            this._mediaElement.DownloadProgressChanged -= new RoutedEventHandler(this.MediaElement_DownloadProgressChanged);
            this._mediaElement.LogReady -= new LogReadyRoutedEventHandler(this.MediaElement_LogReady);
            this._mediaElement = null;

This should Close the file and allow access to the file once again.

Another problem is, when using a PlayReady Video File (.pyv) encoded with Expression Encoder 3 and protected using the PlayReadyPackaging, persisted in the local system, it plays fine, but when I try to perform a seek (change chapter or seek to position in the OnScrubbing) it takes a very long time to perform the action (about 40 seconds in a ace PC)... I was assuming it was a bug in the SSME itself, but when I tried the same with a identical media, encoded with Expression Encoder 4 PRO, it works just fine (less then a second to perform the seek. Do you have any idea of how to fix this without encoding again my media files (have over 10000 videos packaged).

Thanks in advance. Best regards.

Raul Mainardi Neto