Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Controlling the number of times the user can watch a video

 
Reham Omar
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear All,

I have an HTML page with an embedded video.And I want to control the number of times the user can watch this video, for example for only 3 times. How can i do this ??

Best Regards,

Reham
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It depends on your definition of "the user".
Can you tell us what you mean by user?
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Really needs to be controlled at a server level. JavaScript has no real way of preventing this.

Eric
 
Reham Omar
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The user is the one watching the video (using the HTML). I mean i want the viewer to be able to press play twice only then it is disabled.
 
Paul Clapham
Sheriff
Posts: 21316
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Reham Omar:
The user is the one watching the video (using the HTML). I mean i want the viewer to be able to press play twice only then it is disabled.
So if a second person walked up to the computer, you would want the play button to be enabled again so that the second person could watch the video?
 
Reham Omar
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, Assuming only one user per computer, This user(using the HTML) can only watch the viedo a certain number of times(for example 2 ). He can not keep pressing the play button and watch it any number of times.
Sorry for not being specific.
[ April 21, 2007: Message edited by: Reham Omar ]
 
Hussein Baghdadi
clojure forum advocate
Bartender
Posts: 3479
Clojure Mac Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As Eric said, that needs to be controlled at a server level.
For example, let the user logs in and then you can control activity.
He can not keep pressing the play button and watch it any number of times.

Well, I'm not the best person to talk about JavaScript but I think you can employ it here.
But JavaScript here alone is useless with the required server side logic.
 
Reham Omar
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Even if the user is logged and from the servlet i checked that that user can only watch it 2 times, how can this be handled in the server, I still can not get the picture !!
 
Hussein Baghdadi
clojure forum advocate
Bartender
Posts: 3479
Clojure Mac Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Reham,
I'm not sure I got what you mean.
More details please.
 
Reham Omar
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For example, we are in a listening test, i want the person taking the exam to be able to listen the the question only 2 times but not more.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65111
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That all greatly depends upon what kind of controls you are using on the page to start the video/sound. Is it possible to get an event notification when the "Play" button is pressed?

If so, perhaps you could make an Ajax request to the server that asks "permission" to proceed. The server would keep track of things in the session.

It'd be important to make sure that the state persists across page loads so that a Refresh doesn't reset any coutners and so on...
 
Reham Omar
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That all greatly depends upon what kind of controls you are using on the page to start the video/sound. Is it possible to get an event notification when the "Play" button is pressed?


Well I do not understand what you mean by this ? And how i can get this event ??
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65111
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Reham Omar:
And how i can get this event ??


That is, indeed, the million-dollar question. Without knowing a great deal more about how you are playing the video/sounds, no one can say.
 
Reham Omar
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am playign the video using this code

Is there i was to disable the controls of the media player after pressing on play for two times.

I am not sure if this is the correct way to be able to play and stop the video a certain number of times but I do not know anyway!
 
Roger F. Gay
Ranch Hand
Posts: 408
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could put the object in a div and in response to maximum number of tries completed, set div_id.innerHTML =""; On each click, simply test if div_innerHTML = "";

If you don't like innerHTML, use getElementById(div_id).
 
Reham Omar
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Roger F. Gay:
You could put the object in a div and in response to maximum number of tries completed, set div_id.innerHTML =""; On each click, simply test if div_innerHTML = "";

If you don't like innerHTML, use getElementById(div_id).


My problem is how will i find the maximum number of tries? How will I know that the user pressed the play button twice ?? I am sorry for asking too much but I do not know how to do this.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65111
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're obviously using a browser plugin to play the video. You'll need to learn more about the plugin and how it works in order to find out if it has the hooks you need to accomplish what you are attempting.
 
Roger F. Gay
Ranch Hand
Posts: 408
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Reham Omar:


My problem is how will i find the maximum number of tries? How will I know that the user pressed the play button twice ?? I am sorry for asking too much but I do not know how to do this.



If you can call a javascript function in response to the click, and let the javascript function trigger audio, you can also have it keep count of the number of times the audio has been requested. How simple that is depends on how much you want to keep track of and for how long. If you just want to know whether a button has been clicked twice in one page (that is not being reloaded); ++count; ... if (count >= max_clicks) ... The problem that page loading would reset things, means that you have to come up with a way to disallow reloading or to keep track of clicks number of clicks outside the page so that reloading wouldn't matter.

If you do either of those things in javascript, it still might not solve all your problems though. What happens if there's a problem with the audio, and the user doesn't really get to hear it even though they've requested it? Is there feedback from the audio plug-in that can report back to your page? Now ... that's moving back toward depending on processes not in the web page. But you asked ... and this is just a suggestion about something that can be done in javascript.
[ April 22, 2007: Message edited by: Roger F. Gay ]
 
Roger F. Gay
Ranch Hand
Posts: 408
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One approach to guard against reload:


<html>
<head>
<script type="text/javascript">
function setchange () {
window.onresize=change();
}

function change () {
document.location = "reload3.htm";
}
</script>
</head>
<body>
This is no. 2
<input type="submit" value="click" onclick="javascript:void(setchange())" />
</body>
</html>
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic