         cleanUpSource()
         
         // if was playing a previous video, let's remove it now
-        if (videoPlayer.element)
-            videoGateway.removeElement(videoPlayer.element);
-        
-        var videoElement:org.osmf.video.VideoElement;
+        if (videoPlayer.media && videoContainer.containsMediaElement(videoPlayer.media))
+        {
+            videoContainer.removeMediaElement(videoPlayer.media);
+        }
+        
+        var videoElement:org.osmf.media.MediaElement = null;
         
         // check for 4 cases: streaming video, progressive download, 
         // an IMediaResource, or a VideoElement.  

        addEventListener(Event.ADDED_TO_STAGE, addedToStageHandler);
        addEventListener(Event.REMOVED_FROM_STAGE, removedFromStageHandler);
        
        // Set the TLF hook used for localizing runtime error messages.
        // TLF itself has English-only messages,
        // but higher layers like Flex can provide localized versions.
        OSMFStrings.resourceStringFunction = getResourceString;
    }

        
        // set videoPlayer's element to the newly constructed VideoElement
        // set the newly constructed videoElement's gateway to be the videoGateway
        videoPlayer.media = videoElement;
        
        if (videoElement)
        {

            if (videoElement.getMetadata(LayoutMetadata.LAYOUT_NAMESPACE) == null)
            {
                var layout:LayoutMetadata = new LayoutMetadata();
                layout.scaleMode = scaleMode;
                layout.verticalAlign = VerticalAlign.MIDDLE;
                layout.horizontalAlign = HorizontalAlign.CENTER;
                layout.percentWidth = 100;
                layout.percentHeight = 100;
                videoElement.addMetadata(LayoutMetadata.LAYOUT_NAMESPACE, layout);
            }				

            if (videoElement && !videoContainer.containsMediaElement(videoElement) )
            {
                videoContainer.addMediaElement(videoElement);
            }				
        }
        else
        {
