How to change playback rate in jwplayer - javascript

I want to change the playback speed of video in HTML5 mode of jwplayer. I am not interested in flash browser, we will be restricting this feature only for HTML5 browsers
Issue:
I tried changing the playbackrate for HTML5 in jwplayer but playbackrate is coming undefined
i am attaching my code below
jwplayer('my-video').setup({
sources: [
{file:'./test.mp4' , type: "mp4" },
],
width:'640px',
height:'360px',
image : './test.jpg'
});
$("#speed_10").click(function() {
myVid=$( "#my-video" ).find('.jwvideo').find('video');
alert(myVid.length);
alert($( "#my-video" ).find('.jwvideo').find('video').attr('src'))
alert(myVid.playbackRate)
alert($( "#my-video" ).find('.jwvideo').find('video').length)
$( "#my-video" ).find('.jwvideo').find('video').PlaybackRate=0.5;
});
1st alert coming as 1
2nd alert coming undefined
3rd alert is showing "source"
4th alert is 1
I am able to catch the div but not able to change the playback rate in jquery !!!
http://www.longtailvideo.com/support/forums/jw-player/feature-suggestions/32556/playbackrate-support/
following above link i also tried with java script and it worked using code below
(document.getElementsByTagName('video')[0].playbackRate=0.2.
but if i use above code how do i use this for multiple video since there is no ID involved in above code [no unique id is passed for above javascript]
Below is the div structure for the jwplayer

I found the answer for this, main issue which i faced for multiple video was how to make each video unique.i just had to get div by ID first and after get 'Video' tag than change playbackrate
adding the code below
var video = document.getElementById('exampleId')
var video_speed = video.getElementsByTagName('video')[0]
alert(video_speed.playbackRate)
video_speed.playbackRate=0.2;
alert(video_speed.playbackRate)
I even tried with multiple video, it worked fine

Found this script manually manipulating the DOM for custom speeds:
<script type="text/javascript">
jwplayer("video").setup({
image: 'https://<your_CDN_ID>.cloudfront.net/static/splash/<splash.png>',
width: 960,
height: 600,
flashplayer: "https://<your_CDN_ID>.cloudfront.net/assets/jwplayer.flash.swf",
html5player: "https://<your_CDN_ID>.cloudfront.net/assets/jwplayer.html5.js",
primary: 'html5',
sources: [
{ file: 'https://<your_CDN_ID>.cloudfront.net/static/videos/<video>.mp4' },
{ file: 'https://<your_CDN_ID>.cloudfront.net/static/videos/<video>.webm' }
]
});
var tag;
jwplayer().onReady(function(){
if (jwplayer().getRenderingMode() == "flash") {
return;
}
tag = document.querySelector('video');
tag.defaultPlaybackRate = 1.0;
tag.playbackRate = 1.0;
jwplayer().addButton("https://<your_CDN_ID>.cloudfront.net/assets/25.png", "", function(){
jwplayer().seek(jwplayer().getPosition());
tag.playbackRate = 0.25;
},"025");
jwplayer().addButton("https://<your_CDN_ID>.cloudfront.net/assets/05.png", "", function(){
jwplayer().seek(jwplayer().getPosition());
tag.playbackRate = 0.5;
},"05");
jwplayer().addButton("https://<your_CDN_ID>.cloudfront.net/assets/1.png", "", function() {
jwplayer().seek(jwplayer().getPosition());
tag.playbackRate = 1.0;
},"1");
jwplayer().addButton("https://<your_CDN_ID>.cloudfront.net/assets/125.png", "", function() {
jwplayer().seek(jwplayer().getPosition());
tag.playbackRate = 1.25;
},"125");
jwplayer().addButton("https://<your_CDN_ID>.cloudfront.net/assets/15.png", "", function() {
jwplayer().seek(jwplayer().getPosition());
tag.playbackRate = 1.5;
},"15");
jwplayer().addButton("https://<your_CDN_ID>.cloudfront.net/assets/2.png", "", function() {
jwplayer().seek(jwplayer().getPosition());
tag.playbackRate = 2.0;
},"2");
});
</script>
Instead of toggle like the excellent blogpost from Ethan there are speed buttons.
Just setting a custom speed:
document.querySelector('video').playbackRate=0.80;

https://developer.jwplayer.com/jw-player/demos/advanced/set-playback-rate/
only add line playbackRateControls in .setup()
jwplayer('user-player').setup({
playlist: 'https://cdn.jwplayer.com/v2/media/gaCRFWjn',
// Set the available playback rates of your choice
playbackRateControls: [0.75, 1, 1.25, 1.5]
});

Just add ids to your videos and use document.getElementsById (id) instead of document.getElementsByTagName.
document.getElementsById('yourid').playbackRate=0.2

I wrote a blog post about a how to do this in the JW Player, by the way. It might be helpful! - http://www.longtailvideo.com/blog/33860/slow-motion-with-jw-player

Related

Javascript play audio when loaded

so I have a code for volume slider. What it does is that it plays sound when you have changed volume after loading the slider. For example if default value of the slider is 50 it wont play sound right after loading the audio file, you need to change value to higher or lower so sound can come out. So I need help with JavaScript. What can I do so it starts playing the sound whenever is loaded?
Full code : https://www.w3schools.com/code/tryit.asp?filename=FQZVZUX36JFD
JS:
$("#volume").slider({
min: 0,
max: 100,
value: 50,
range: "min",
slide: function(event, ui) {
setVolume(ui.value / 100);
}
});
var myMedia = document.createElement('audio');
$('#player').append(myMedia);
myMedia.id = "myMedia";
playAudio('http://listen.shoutcast.com/newfm64aac-', 0);
function playAudio(fileName, myVolume) {
myMedia.src = fileName;
myMedia.setAttribute('loop', 'loop');
setVolume(myVolume);
myMedia.play();
}
function setVolume(myVolume) {
var myMedia = document.getElementById('myMedia');
myMedia.volume = myVolume;
}
Google recently released a browser update that prevents initial playing or autoplaying of media elements (Note: not the solution for this answer, but a potential solution for similar cases.)
You're setting the initial volume to zero with this call:
playAudio('http://listen.shoutcast.com/newfm64aac-', 0);
To have it load at a default of 50 your call should be:
playAudio('http://listen.shoutcast.com/newfm64aac-', 50);

VIdeo playback not working on samsung tv

I created a sample application using samsung tv sdk and added video player with the bellow code.but it does not playing my video
SceneScene1.prototype.initialize = function () {
alert("SceneScene1.initialize()");
// this function will be called only once when the scene manager show this scene first time
// initialize the scene controls and styles, and initialize your variables here
// scene HTML and CSS will be loaded before this function is called
sf.service.VideoPlayer.init({
onend:function(){
sf.service.VideoPlayer.setFullScreen(false);
}
});
sf.service.VideoPlayer.setKeyHandler(sf.key.RETURN,
function(){
sf.service.VideoPlayer.setFullScreen(false);
});
var vLeft = parseInt($("#svecVideo_y5ww").css('left'));
var vTop = parseInt($("#svecVideo_y5ww").css('top'));
var vHeight = parseInt($("#svecVideo_y5ww").css('height'));
var vWidth = parseInt($("#svecVideo_y5ww").css('width'));
sf.service.VideoPlayer.setPosition({
left:vLeft,
top:vTop,
width:vWidth,
height:vHeight
});
sf.service.VideoPlayer.show();
sf.service.VideoPlayer.play({
url: 'http://media.w3.org/2010/05/sintel/trailer.mp4',
fullScreen: false,
title: 'Samsung movie',
startTime: 5,
liveStream: false,
timeString: true,
authHeader: 'none'
});
};
and if we try to inspect using web inspector.it shows the bellow errors
Service is unavailable due to network or service interference.
The file can't be played because the format isn't supported.
Unable to play the file. Please check it and try again later.
i tried with different files,and shows the same error

Cretive SDK Image Editor UI not show custom, resizable text (WEB)

I made one email app where I want to use Adobe Creative SDK for editing images and adding text over image. All works almost great but when I click on "text" button and trying to add new layer (Add Text) I not see anything. All options is there, no erros in console just text layer not show up and I'm unable to insert text over image.
Here is my setup:
var featherEditor = new Aviary.Feather({
apiKey: '[MY-ID]',
tools : ['text','crop','resize','color'],
fileFormat : 'png,jpg,gif,jpeg',
theme:'light',
displayImageSize : true,
onSave: function(imageID, newURL) {
var img = document.getElementById(imageID);
img.src = newURL;
}
});
function launchEditor(id, src) {
featherEditor.launch({
image: id,
url: src,
cropPresets: [
'Original',
['Mail App','600x600'],
'4:3',
'16:9'
],
});
return false;
}
I also remove my CSS from this page and leave clean Adobe library and nothing chaged.
Can anyone help me?
I find solution for my problem. I just add one CSS code:
#avpw_canvas_element.avpw_position_by_transform {
z-index: 0;
}
This fix my layering problem and all work great.

Fading out the page while a youtube video is playing

How can you fade out /or place a black semi-transparent cover over the entire page when an embedded youtube video is playing and have it go back to normal when the video is over or paused?
javascript?
jquery?
This is as far as I got, I don't know enough coding (just html/css) to use it though:
https://developers.google.com/youtube/js_api_reference#Adding_event_listener
I figured out how to use the API to call the video and have some event listener code I found in the API to call functions on state changes (ex play and end video), though I'm not sure why the listener part isn't working.. I don't have any experience with API's or javascript at this level..
$(document).ready(function(){
var params = { allowScriptAccess: "always" };
var atts = { id: "myytplayer" };
swfobject.embedSWF(
"http://www.youtube.com/v/TEHWDA_6e3M?enablejsapi=1&playerapiid=ytplayer&version=3",
"ytapiplayer",
"960",
"540",
"8",
null,
null,
params,
atts
);
function onYouTubePlayerReady(playerId) {
ytplayer = document.getElementById("myytplayer");
ytplayer.addEventListener("onStateChange", "onytplayerStateChange");
}
function onytplayerStateChange(newState) {
alert("Player's new state: " + newState);
}
});
Place a div with position:fixed and background-color: rgba(0, 0, 0, 0.75) that covers the entire page and then place the video on top of it by listening for the onStateChanged event from the player. You will have to use the javascript player api for this to work.

How to send a seek event to player embedded with SWFObject 2.2?

I have updated my SWFObject to 2.2 from 1.5 and now need to replicate some old functionality that used to work in 1.5, viz an event jumping to a certain point in the video.
Here's the contents of my script tag:
var flashvars = {
file: '79834.flv',
autostart: 'true',
displayclick: 'mute',
repeat: 'single',
start: 0
};
var params = {
allowfullscreen: "true",
allownetworking: "all",
allowscriptaccess: "always"
};
swfobject.embedSWF("player.swf","main","500","400","9.0.0", "false", flashvars, params);
var player;
function playerReady(obj) {
player = document.getElementById(obj.id);
alert(player);
setTimeout("seek()", 1000);
}
function seek() {
player.sendEvent("SEEK", 100);
}
The top half is what I've replaced the old V1.5 code with.
The bottom half (from "var player") is what no longer works. playerReady is still happening, but apparently obj.id is now "null". Is there a new correct way to find the player element? Or a different way to implement a seek event?
You missed the id attribute:
var attributes = {
id: "playerID"
}
// and later
swfobject.embedSWF("player.swf","main","500","400","9.0.0", "false", flashvars, params, attributes);

Categories