video player height - part 2

I had a good solution at: http://www.experts-exchange.com/questions/28735879/video-player-height.html from Julian Hansen. This is part two of the same question.

In the below image:
1: Small video player appears. For now I am fine with this.
2: When play button (on 1) is clicked on, this screen plays the video. This is good.
3: When pause button (on 2) is clicked on, the video stops. This is good.
4: But, when play (on 3) is clicked again, immediately it changes to image 4 while the video continues playing.
Videos2Question: How this problem could be corrected?

Problem: On 3, on play-click continues playing but only after reducing its size. The code needs to be revised to prevent changing its size on play. The size ought to be reduced on after video play gets to its end.

Additionally, if user lets video finish up in image 3, ideally, it should shrink back to its iconic size after say 3 or 4 seconds delay. Sorry, if this is too much, I will be happy to break this question to a few.
<video height="100" controls data-height="500">
      <source src="http://www.sample-videos.com/video/mp4/720/big_buck_bunny_720p_1mb.mp4" type="video/mp4">
      Your browser does not support HTML5 video.
    </video>

Open in new window

<script>
$(function() {
  $('video').on('play', function (e) {
    // SAVE THE CURRENT HEIGHT
    var saved = $(this).height();
  
  // GET THE NEW HEIGHT DEFAULT TO 400 IF NOT SET
  var newheight = $(this).data('height') || 400;
  
  // SET THE NEW HEIGHT
    $(this).css({height: newheight + 'px'});
  
  // STORE THE OLD HEIGHT FOR WHEN DONE
  $(this).data('height', saved);
  });
  
  $('video').on('ended', function (e) {
    // SAVE THE CURRENT HEIGHT
    var fullheight = $(this).height();
  
    // GET THE OLD HEIGHT DEFAULT TO 100 IF NOT SET
    var newheight = $(this).data('height') || 100;
	
    // SET THE DEFAULT HEIGHT
    $(this).css({height: newheight + 'px'});
  
    // RESTORE THE FULL HEIGHT VALUE
    $(this).data('height', fullheight);
  });
});
</script>

Open in new window

LVL 34
Mike EghtebasDatabase and Application DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Julian HansenCommented:
Easily fixed - the problem was that the play event was triggering after the pause so it was effectively causing the video to toggle backwards and forwards between max and min height.

This change will fix that - it
<script>
$(function() {
  $('video').on('play', function (e) {
    // IGNORE PLAY EVENT IF ALREADY RESIZED
    if ($(this).data('oldheight') > 0) return;
  
    // SAVE THE CURRENT HEIGHT
    $(this).data('oldheight', $(this).height());
  
    // GET THE NEW HEIGHT DEFAULT TO 400 IF NOT SET
    var newheight = $(this).data('height') || 400;
  
    // SET THE NEW HEIGHT
    $(this).css({height: newheight + 'px'});
  });
  
  $('video').on('ended', function (e) {
    // GET THE OLD HEIGHT DEFAULT TO 100 IF NOT SET
    var oldheight = $(this).data('oldheight') || 100;
	
    // SET THE DEFAULT HEIGHT
    $(this).css({height: oldheight+ 'px'});
  
    // RESTORE THE FULL HEIGHT VALUE
    $(this).data('oldheight', 0);
  });
});
</script>

Open in new window

Updated sample here
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
This is real nice. Thank you.

There is a related followup question at: http://www.experts-exchange.com/questions/28736185/Player-button-shape.html

if you have a moment to take a look at.

Mike
0
Julian HansenCommented:
Again you are welcome and thank you.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.