######################################################################################################
#
# SMPfixes.patch, 20120330, Alexander Grahn
#
# Patch for StrobeMediaPlayback version 1.6.328 sources
# http://sourceforge.net/projects/smp.adobe/files/
#
######################################################################################################
# fix: video could not be restarted after having ended if AS variable `autoRewind' was set to `false'
# new: show first frame of video as default poster instead of black stage
# new: play/pause video by clicking on the stage
######################################################################################################
--- ./player/StrobeMediaPlayback/src/org/osmf/player/chrome/widgets/PlayButtonOverlay.as.orig	2012-03-23 16:04:41.000000000 +0100
+++ ./player/StrobeMediaPlayback/src/org/osmf/player/chrome/widgets/PlayButtonOverlay.as	2012-03-26 13:23:52.000000000 +0200
@@ -98,6 +98,11 @@
 		override protected function onMouseClick(event:MouseEvent):void
 		{
 			var playable:PlayTrait = media.getTrait(MediaTraitType.PLAY) as PlayTrait;
+			var seekable:SeekTrait = media.getTrait(MediaTraitType.SEEK) as SeekTrait;
+			if(playable.playState == PlayState.STOPPED)
+			{
+				try{seekable.seek(0);}catch(e:Object){}
+			}
 			playable.play();
 		}
 		
--- ./player/StrobeMediaPlayback/src/org/osmf/player/chrome/widgets/PlayButton.as.orig	2012-03-26 13:22:33.000000000 +0200
+++ ./player/StrobeMediaPlayback/src/org/osmf/player/chrome/widgets/PlayButton.as	2012-03-26 16:03:07.000000000 +0200
@@ -26,6 +26,7 @@
 	import org.osmf.traits.MediaTraitType;
 	import org.osmf.traits.PlayState;
 	import org.osmf.traits.PlayTrait;
+	import org.osmf.traits.SeekTrait;
 	
 	public class PlayButton extends PlayableButton
 	{
@@ -44,6 +45,11 @@
 		override protected function onMouseClick(event:MouseEvent):void
 		{
 			var playable:PlayTrait = media.getTrait(MediaTraitType.PLAY) as PlayTrait;
+			var seekable:SeekTrait = media.getTrait(MediaTraitType.SEEK) as SeekTrait;
+			if(playable.playState == PlayState.STOPPED)
+			{
+				try{seekable.seek(0);}catch(e:Object){}
+			}
 			playable.play();
 			event.stopImmediatePropagation();
 		}
--- ./player/StrobeMediaPlayback/src/org/osmf/player/chrome/widgets/Slider.as.orig	2012-03-29 16:54:07.000000000 +0200
+++ ./player/StrobeMediaPlayback/src/org/osmf/player/chrome/widgets/Slider.as	2012-03-29 16:54:15.000000000 +0200
@@ -106,7 +106,7 @@
 			if (_enabled && _sliding == false)
 			{
 				_sliding = true;
-				stage.addEventListener(MouseEvent.MOUSE_UP, onStageExitDrag);
+				stage.addEventListener(MouseEvent.MOUSE_UP, onStageExitDrag, true);
 				updateFace(down);
 				scrubTimer.start();
 				dispatchEvent(new ScrubberEvent(ScrubberEvent.SCRUB_START));
--- ./player/StrobeMediaPlayback/src/StrobeMediaPlayback.as.orig	2012-03-23 15:44:09.000000000 +0100
+++ ./player/StrobeMediaPlayback/src/StrobeMediaPlayback.as	2012-03-30 15:00:42.000000000 +0200
@@ -51,6 +51,7 @@
 	import org.osmf.traits.MediaTraitType;
 	import org.osmf.traits.PlayState;
 	import org.osmf.traits.PlayTrait;
+	import org.osmf.traits.SeekTrait;
 	import org.osmf.utils.OSMFSettings;
 	import org.osmf.utils.OSMFStrings;
 	
@@ -151,6 +152,7 @@
 			
 			player.addEventListener(TimeEvent.COMPLETE, onComplete);
 			player.addEventListener(MediaErrorEvent.MEDIA_ERROR, onMediaError);
+			player.addEventListener(MediaPlayerCapabilityChangeEvent.CAN_PLAY_CHANGE, onCanPlayChange);
 			
 			// this is used for DVR rolling window
 			// TODO: Add this event only when the resource is DVR rolling window not all the time
@@ -266,6 +268,8 @@
 			mainContainer.backgroundAlpha = 0;
 			mainContainer.addEventListener(MouseEvent.DOUBLE_CLICK, onFullScreenRequest);
 			mainContainer.addEventListener(MouseEvent.CLICK, onMainClick, false);
+			mainContainer.addEventListener(MouseEvent.MOUSE_DOWN, onMainDown, false);
+			mainContainer.addEventListener(MouseEvent.MOUSE_UP, onMainUp, false);
 			mainContainer.doubleClickEnabled = true;
 			
 			addChild(mainContainer);
@@ -343,6 +347,9 @@
 				}
 
 				player.addEventListener(PlayEvent.PLAY_STATE_CHANGE, onSetAutoHide);
+
+				controlBarContainer.addEventListener(MouseEvent.MOUSE_DOWN, onControlBarAny, false);
+				controlBarContainer.addEventListener(MouseEvent.MOUSE_UP, onControlBarAny, false);
 					
 				layout();
 				
@@ -654,6 +661,38 @@
 			}
 		}
 		
+		private function onMainDown(event:MouseEvent):void
+		{
+			var playable:PlayTrait = player.media.getTrait(MediaTraitType.PLAY) as PlayTrait;
+			if (playable.playState == PlayState.PLAYING)
+			{
+				playable.pause();
+			}
+		}
+		
+		private function onMainUp(event:MouseEvent):void
+		{
+			var playable:PlayTrait = player.media.getTrait(MediaTraitType.PLAY) as PlayTrait;
+			var seekable:SeekTrait = player.media.getTrait(MediaTraitType.SEEK) as SeekTrait;
+			if(playable.playState == PlayState.STOPPED)
+			{
+				if(player.canSeek){seekable.seek(0);}
+				playable.play();
+			}
+			else if(playable.playState == PlayState.PAUSED)
+			{
+				playable.play();
+			}
+		}
+		
+		private function onControlBarAny(event:MouseEvent):void
+		{
+		    if(event.eventPhase == EventPhase.BUBBLING_PHASE)
+			{
+				event.stopImmediatePropagation();
+			}
+		}
+		
 		/**
 		 * Toggles full screen state.
 		 */ 
@@ -928,12 +967,20 @@
 				&&	configuration.endOfVideoOverlay != ""
 				&&	player.loop == false
 				&&	player.playing == false
+				&&	player.autoRewind == true
 			)
 			{
 				processPoster(configuration.endOfVideoOverlay);
 			}	
 		}
 		
+		private function onCanPlayChange(event:MediaPlayerCapabilityChangeEvent):void
+		{
+			// Make sure this event gets handled only once:
+			player.removeEventListener(event.type, arguments.callee);
+			player.play(); player.stop();
+		}
+
 		private function onMediaError(event:MediaErrorEvent):void
 		{
 			// Make sure this event gets handled only once:
