SWFObject v2.2 auto-play

2,206 views
Skip to first unread message

Amit

unread,
Feb 9, 2010, 4:55:03 PM2/9/10
to SWFObject
Is it possible to auto-play .flv or .f4v file using SWFObject v2.2?

Aran Rhee

unread,
Feb 9, 2010, 5:15:36 PM2/9/10
to swfo...@googlegroups.com
Autoplaying a video has nothing to do with SWFObject directly. This is controlled by whatever flash file your are embedding on your page to load and play the video.

Aran

On Wed, Feb 10, 2010 at 8:55 AM, Amit <amit.si...@gmail.com> wrote:
Is it possible to auto-play .flv or .f4v file using SWFObject v2.2?

--
You received this message because you are subscribed to the Google Groups "SWFObject" group.
To post to this group, send email to swfo...@googlegroups.com.
To unsubscribe from this group, send email to swfobject+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/swfobject?hl=en.


Sam Sherlock

unread,
Feb 9, 2010, 5:20:14 PM2/9/10
to swfo...@googlegroups.com
This depends on the flv-player your 

SWFObject embeds the swf; if the mediaplayer your using has autoplay/autostart  then you can embed that & setup the flashvars that set autoplay

eg with the longtail player you enable autostart with a flashvar

autostart = true

the longtail player has docs/forums etc of its own

- S




On 9 February 2010 21:55, Amit <amit.si...@gmail.com> wrote:
Is it possible to auto-play .flv or .f4v file using SWFObject v2.2?
Message has been deleted

Amit

unread,
Feb 9, 2010, 10:47:48 PM2/9/10
to SWFObject
Hi,

I am using SWFObject v2.2 <http://code.google.com/p/swfobject/> to
play swf/flv files.

I have tried two different SWFObject files to auto-play same .flv
file. Auto-play is not working in case of "SWFObject V2.2 <http://
code.google.com/p/swfobject/>" but it worked when I used "SWFObject
v1.4.4: Flash Player detection and embed - http://blog.deconcept.com/swfobject/"

I can not use "SWFObject v1.4.4" because there is lot of dependency on
the version (SWFObject v2.2) that I am using right now. Please check
the following page to see my problem :

http://www.merck.com/research/discovery-and-development/home.html

There is one video image on the right side panel. Player will be
loaded when you click on this image. I want to make it auto-play
whenever user clicked on this image.

Here is my method that I have used-

Site.MediaPlayer = {
// minimum required flash version
FlashVersionRequired : '9.0.0.0',
// url of the main flash movie
PlayerSwfURL : '/includes/audio-video/mediaPlayer/
Main.swf',
flashSupported : false,
// default flashvars params
ParamObjDefaults : {
fontsURL : '/includes/audio-video/mediaPlayer/swf/
fonts.swf',
stylesURL : '/includes/audio-video/mediaPlayer/css/
mpstyles.css',
playlistURL : '',
skinURL : '',
mediaURL : '',
mediaType : '',
audio : '',
videoimg : '',
overlay : ''
},
// basic movie loading/creation function
Load : function(paramObj, targetElement) {
// merge defaults with override value.
var playerParams = {};
for (var i in Site.MediaPlayer.ParamObjDefaults) {
var defaultName = i;
var defaultValue =
Site.MediaPlayer.ParamObjDefaults[i];
var setValue = paramObj[defaultName];
var mergedValue = (setValue != undefined) ?
setValue : defaultValue;
playerParams[i] = mergedValue;
}
// set default skin if override not present
if (playerParams.skinURL == '') {
playerParams.skinURL =
Site.MediaPlayer.Skins[playerParams.mediaType.toLowerCase()];
}
// find media features, if included. This could probably be
refined but it works for now.
if (playerParams.mediaType == 'video' &&
playerParams.playlistURL != '') { var mediaFeature = 'gallery'; }
else if (playerParams.mediaType == 'image' &&
playerParams.audio == 'true') { var mediaFeature = 'audio'; }
// get dimensions for media type, or mediaType + mediaFeature
var dimensions =
Site.MediaPlayer.Dimensions[playerParams.mediaType];
dimensions = (mediaFeature &&
dimensions[mediaFeature]) ? dimensions[mediaFeature] : dimensions;
// general swf params for the player
var swfParams = {
allowFullScreen:'true',
menu:'false',
wmode:'transparent'
};
var swfAttrs = {};
// show some handy logging info for debug purposes
if (typeof(console.log) == 'function') {
/* console.log('PLAYER URL',
Site.MediaPlayer.PlayerSwfURL);
console.log('TARGET ELEMENT', targetElement ||
'MODAL');
console.log('PLAYERPARAMS', playerParams);*/
}
// NOTE: the following chunk of code is a workaround for a
swfObject design issue.
// swfObject expects an id string to represent the target
element ... which is not
// ideal to say the least for general-purpose embedding in raw
elements. to make
// up for this problem we look at the target element, and
check it for an ID. If
// it has one, we use it. If not, we assign it a random ID and
then use that.
if (targetElement && typeof(targetElement) !=
'string') {
var targetID = $(targetElement).attr('id');
if (!targetID) {
var targetID =
'mediaplayerrandomidgen-'+(Math.round(Math.random()*100000));
while
(document.getElementById(targetID)) {
var targetID =
'mediaplayerrandomidgen-'+(Math.round(Math.random()*100000));
}
$(targetElement).attr('id',
targetID);
playerParams.overlay = '';
}
} else if (!targetElement) {
modal.enter('<div
id="ModalMediaPlayerParent"></div>')
var targetID = 'ModalMediaPlayerParent';
playerParams.overlay = 'true';
}
// go ahead and embed the swf with swfobject.
if (Site.MediaPlayer.flashSupported) {
swfobject.embedSWF(
Site.MediaPlayer.PlayerSwfURL,
targetID,
dimensions.width,
dimensions.height,

Site.MediaPlayer.FlashVersionRequired,
'expressInstall.swf',
playerParams,
swfParams,
swfAttrs
);
} else if (!Site.MediaPlayer.flashSupported &&
targetID == 'ModalMediaPlayerParent' ) {
modal.enter('<div
id="ModalMediaPlayerParent"><h1>To view this content, you need the
flash player</h1><h1><a href="http://adobe.com/getflash/"
target="_blank">download the flash player here.</a></h1></div>');
}
},
// media-specific load functions
loadVideo : function(paramObj, targetElement) {
paramObj.mediaType = 'video';
Site.MediaPlayer.Load(paramObj, targetElement);
},
loadAudio : function(paramObj, targetElement) {
paramObj.mediaType = 'audio';
Site.MediaPlayer.Load(paramObj, targetElement);
},
loadImage : function(paramObj, targetElement) {
paramObj.mediaType = 'image';
Site.MediaPlayer.Load(paramObj, targetElement);
},
// initialization of link-scheme items
Init : function() {
// detect support
Site.MediaPlayer.flashSupported =
(swfobject.getFlashPlayerVersion().major >=
parseInt(Site.MediaPlayer.FlashVersionRequired.charAt(0)));
// audioLinkage
$('a[href^=http://get.adobe.com/flashplayer/
#mediaPlayer/loadAudio:]').each(function(){
var playerWrap = $(this);
playerWrap.click(function(){if
(Site.MediaPlayer.flashSupported) { return false; }})
var audioPath =
playerWrap.attr('href').split('loadAudio:')[1].split('&')[0];
Site.MediaPlayer.loadAudio({
mediaURL : audioPath
}, playerWrap.get(0));
});
//imageLinkage
$('a[href^=http://get.adobe.com/flashplayer/
#mediaPlayer/loadImage:]').each(function(){
var playerWrap = $(this);
var playlistURL =
playerWrap.attr('href').split('loadImage:')[1];
var audioSTR = ((/\&audio
\:true/).test(playerWrap.attr('href'))) ? 'true': '';
var inline = ((/\&inline
\:true/).test(playerWrap.attr('href'))) ? playerWrap.get(0): null;
var makeMovie = function() {
Site.MediaPlayer.loadImage({
playlistURL :
playlistURL,
audio :
audioSTR
}, inline);
}
if (inline) {
makeMovie();
playerWrap.click(function(){
if
(Site.MediaPlayer.flashSupported) { return false; }
});
} else{
playerWrap.click(function(){
makeMovie();
return false;
});
}
});
//videoLinkage
$('a[href^=http://get.adobe.com/flashplayer/
#mediaPlayer/loadVideo:]').each(function(){
var playerWrap = $(this);
var playlistURL =
playerWrap.attr('href').split('&playlist:')[1].split('&')[0];
var mediaURL =
playerWrap.attr('href').split('loadVideo:')[1].split('&')[0];
var videoimg =
playerWrap.attr('href').split('&loadImage:')[1].split('&')[0];
var inline = ((/\&inline
\:true/).test(playerWrap.attr('href'))) ? playerWrap.get(0): null;
var makeMovie = function() {
Site.MediaPlayer.loadVideo({
playlistURL : playlistURL,
mediaURL : mediaURL,
videoimg : videoimg
}, inline);
}
if (inline) {
makeMovie();
playerWrap.click(function(){
if
(Site.MediaPlayer.flashSupported) { return false; }
});
} else{
playerWrap.click(function(){
makeMovie();
return false;
});
}
});
},
// Default Skins
Skins : {
video : '/includes/audio-video/mediaPlayer/swf/
videoskin.swf',
audio : '/includes/audio-video/mediaPlayer/swf/
audioskin.swf',
image : '/includes/audio-video/mediaPlayer/swf/
imageskin.swf'
},
// stores dimensions for various states of the mediaPlayer
Dimensions : {
video : {
width:530,
height:336,
gallery: {
width:530,
height:423
}
},
image : {
width:530,
height:340,
audio: {
width:530,
height:360
}
},
audio : {
width:180,
height:21
}
}
};

Please advice.

Thanks,
Amit

On Feb 9, 4:15 pm, Aran Rhee <aran.r...@gmail.com> wrote:
> Autoplaying a video has nothing to do with SWFObject directly. This is
> controlled by whatever flash file your are embedding on your page to load
> and play the video.
>
> Aran
>
>
>
> On Wed, Feb 10, 2010 at 8:55 AM, Amit <amit.singh.g...@gmail.com> wrote:
> > Is it possible to auto-play .flv or .f4v file using SWFObject v2.2?
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "SWFObject" group.
> > To post to this group, send email to swfo...@googlegroups.com.
> > To unsubscribe from this group, send email to

> > swfobject+...@googlegroups.com<swfobject%2Bunsubscribe@googlegroups .com>

Aran Rhee

unread,
Feb 10, 2010, 12:25:27 AM2/10/10
to swfo...@googlegroups.com
So, as I said in my first reply, setting autoplay parameters is nothing to do directly with SWFObject. You need to set whatever value your video player swf is expecting in your Flashvars in order to set the autoplay.

What video player are you using?

Aran



To unsubscribe from this group, send email to swfobject+...@googlegroups.com.

Amit

unread,
Feb 10, 2010, 8:52:56 AM2/10/10
to SWFObject
I am using media-player. How can I set Flashvars in my case? I don't
know how same .flv is working with other SWFObject (I have passed same
parameters in both cases). I am able to auto-play .flv file using
"SWFObject v1.4.4" but auto-play is not working in case of "SWFObject
v2.2". I have used following code to auto-play video in case of
"SWFObject v1.4.4" -

function autoPlayVideo()
{
var vidContent = new SWFObject('http://localhost/mediaplayer.swf',
'playlist', '475', '508', '7');
vidContent .addParam('allowfullscreen', 'true');
vidContent .addVariable('width', '475');
vidContent .addVariable('height', '508');
vidContent .addVariable('displayheight', '350');
vidContent .addVariable('file', 'http://localhost/MyVideo.flv');
vidContent .addVariable('autostart', 'true');
vidContent .addVariable('shuffle', 'false');
vidContent .addVariable('repeat', 'list');
vidContent .write('player'); /* DIV ID */
};

Please help me to achieve similar functionality in case of "SWFObject
v2.2".

Thanks,
Amit

> ...
>
> read more »

Sam Sherlock

unread,
Feb 10, 2010, 9:03:25 AM2/10/10
to swfo...@googlegroups.com
The syntax of swfobject 2.x differs from that of 1.x

with version you make an object for you flashvars:
var flashvars = {
  width: "475",
  autostart: "true",
}

you also make on for params these are then passed to the embed swf call see the documentation for more on this.  Basically what you would pass to addParam with 1.x you put in the params object for 2.x and addVariable args from 1.x are put in the flashvars object (you may also wish to make attribs and pass that also again see the documentation)





- S




--
Reply all
Reply to author
Forward
0 new messages