I looked through similar questions, but they did not help.. I am creating a flash player to use in a Java Vaadin application (according to this blog http://www.derekentringer.com/blog/flex-3-simple-flv-player-scrubbing-pause-play/), the code is below. I compile the project to get test.swf file and use it in a Java application.
The player works fine if I place the source link directly into mxml file, inside the "VideoDisplay" tag (source="rtmp://cp114761.live.edgefcs.net:443/live/tpc-live_1@44263" />
as in the blog) and then compile an use the resulting test.swf.
But it does not play the video if I pass the "source" as a parameter from the java application. For that I compile the player without the "source" parameter inside "VideoDisplay" tag. In this case it only shows the buttons (so the player itself is loaded fine), but the video is not playing.
Would be very grateful for any advice..
Java code:
private Embedded video = new Embedded();
video.setParameter("wmode", "opaque");
video.setParameter("pluginspage","http://www.macromedia.com/go/getflashplayer");
video.setParameter("type", "application/x-shockwave-flash");
video.setParameter("allowfullscreen", "true");
video.setParameter("allowScriptAccess", "always");
video.setParameter("name","flvp2");
video.setParameter("quality", "high");
video.setParameter("sameDomain", "allowscriptaccess");
video.setSource("path/to/resources/flash/test.swf");
video.setParameter("flashVars", "source=rtmp://cp114761.live.edgefcs.net:443/live/tpc-live_1@44263");
Flash code:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" verticalAlign="top" backgroundColor="white" viewSourceURL="srcview/index.html">
<mx:Script>
<![CDATA[
private function formatTime(item:Date):String {
return dateFormatter.format(item);
}
private function videoDisplay_playheadUpdate():void {
var pT:Number = videoDisplay.playheadTime || 0.1;
var tT:Number = videoDisplay.totalTime;
var pTimeMS:Date = new Date(pT * 1000);
var tTimeMS:Date = new Date(tT * 1000);
timeLabel.text = formatTime(pTimeMS) + " / " + formatTime(tTimeMS);
}
private function slider_thumbPress():void {
videoDisplay.pause();
}
private function slider_thumbRelease():void {
videoDisplay.play();
}
private function videoDisplay_ready():void {
videoDisplay.visible = true;
controlBar.visible = true;
}
]]>
</mx:Script>
<mx:DateFormatter id="dateFormatter" formatString="NN:SS" />
<mx:Panel title="{videoDisplay.source.split('/').pop()} ({videoDisplay.state})">
<mx:VideoDisplay id="videoDisplay" visible="false" width="100%" height="100%"
playheadUpdate="videoDisplay_playheadUpdate()"
ready="videoDisplay_ready()"
rewind="videoDisplay.play()"
autoPlay="true"
live="true"
idleTimeout="1000" />
<mx:ControlBar id="controlBar" visible="false">
<mx:Button id="play" name="play" label="Play" click="videoDisplay.play()"></mx:Button>
<mx:Button id="pause" name="pause" label="Pause" click="videoDisplay.pause()"></mx:Button>
<mx:Label id="timeLabel" textAlign="right" />
</mx:ControlBar>
</mx:Panel>
</mx:Application>
In case someone needs it, the answer is to declare a variable in [CDATA[ section of the mxml file:
[Bindable]
private var source:String;
Initialize it:
this.source = FlexGlobals.topLevelApplication.parameters.source;
And use it inside the VideoDisplay tag:
<mx:VideoDisplay id="videoDisplay" visible="true" width="100%" height="100%"
...
source="{source}"/>