New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Making Player Responsive #402
Comments
I checked this example: How to use percentage width and height with bootstrap responsive grid? |
@wicherdt Check this fiddle showing how to make a fluid resize of the player: http://jsfiddle.net/oujfL91o/. When using percentage values, the parent element must have its height defined. In your example, #player will have an automatic height, which by default is the computed size of its children tree. If you add the parameter With a responsive grid, the width parameter is not an issue, because the grid defines the width of the elements according to resolution. You used an external div with the class
to
I believe this will solve your problem. Please note that percentage values are only supported on Clappr 0.0.114 or later. |
Thank you for your help. Bootstrap 3.3.4 Clappr 0.0.114 jQuery 1.11.2 responsive example:
|
@wicherdt Anytime. The resizable function was only to demonstrate the fluid resizing of the player, adding a resize handle so it will adjust to any size you want. Since the player is working on your responsive grid, I'm closing this issue. Please reopen if there are any other problems related to it. |
I'm not using bootstrap and jquery doesn't have a Is there anyway to get a responsive player? |
@leandromoreira I assume i would need to call |
@chovy you can do something like function resizePlayer(){
var aspectRatio = 9/16,
newWidth = document.getElementById('yourplayer').parentElement.offsetWidth,
newHeight = 2 * Math.round(newWidth * aspectRatio/2);
player.resize({width: newWidth, height: newHeight});
}
resizePlayer();
window.onresize = resizePlayer; |
getting an error that |
nm, i had called player before it was defined. |
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<script type="text/javascript" charset="utf-8" src="http://cdn.clappr.io/latest/clappr.min.js"></script>
<title>Clappr Player</title>
</head>
<body>
<div style="overflow:hidden;width:640px;">
<div id="player-wrapper"></div>
</div>
<script type="text/javascript" charset="utf-8">
window.onload = function() {
var player = new Clappr.Player({
parentId: '#player-wrapper',
source: 'http://clappr.io/highline.mp4'
});
function resizePlayer(){
var aspectRatio = 9/16,
newWidth = document.getElementById('player-wrapper').parentElement.offsetWidth,
newHeight = 2 * Math.round(newWidth * aspectRatio/2);
player.resize({width: newWidth, height: newHeight});
}
resizePlayer();
window.onresize = resizePlayer;
}
</script>
</body>
</html> |
For what it's worth, here's a CSS-only solution to making the player responsive:
It'll take up 100% width and use its natural aspect ratio (instead of forcing the aspect ratio through styles). When you create the player, just use:
|
@chovy I want to add a really small "patch" to @me-vlad solution (anyway thanks for this snippet @me-vlad!). It's better to not use So instead of: window.onresize = resizePlayer; it's better to do this (as suggested here): var addEventListener = (function() {
if(document.addEventListener) {
return function(element, event, handler) {
element.addEventListener(event, handler, false);
};
} else {
return function(element, event, handler) {
element.attachEvent('on' + event, handler);
};
}
}());
addEventListener(window, 'resize', resizePlayer); |
Thanks. It would be nice if we could just have an option like On Fri, Sep 16, 2016 at 4:22 AM, paluh notifications@github.com wrote:
Anthony |
@paluh how does using |
I think it is already responsive, check this, you need to put it on a responsive container though. |
@chovy With |
this works with 16/9 for the player? |
@Allan-Nava as described by previous comments, when you set Therefore, if you set these options to For example, using Bootstrap CSS utilities : <html>
<head>
<title>Clappr Bootstap 16/9</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@latest/dist/css/bootstrap.min.css">
<script src="https://cdn.jsdelivr.net/npm/clappr@latest/dist/clappr.min.js"></script>
</head>
<body>
<div class="container">
<!-- 16:9 aspect ratio -->
<div class="embed-responsive embed-responsive-16by9">
<div class="embed-responsive-item player"></div>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
var player = new Clappr.Player({
parentId: '.player',
source: 'https://acme.org/path/to/my-video.mp4',
height: '100%',
width: '100%',
});
});
</script>
</body>
</html> |
also consider a simple way to proportional wrap without bootstrap or js: <div style="width: 100%; max-width: 1280px; margin: auto;">
<div style="position: relative; padding-top: 56.25%;">
<div style="position: absolute; top: 0; right: 0; bottom: 0; left: 0;">
<div id="player-container">
<!-- The player configured 100% by 100% -->
</div>
</div>
</div>
</div> P.S. Inline style is not considered a best practice. I use it for brevity :) |
Okay it works with the bootstrap class! Thanks |
Responsive, players scale to the width of their container element, maintaining the video aspect ratio.
The text was updated successfully, but these errors were encountered: