HTML5 video - playing only a portion of a video - html

Is there some straightforward technique to play only a certain part of a HTML5 video? For example in a 30 second clip I would like to play only the part 5-20 sec. Additionally the rest of the video should not be accessible from the UI at all (meaning the video timeline should only show the 5-20 sec part).
I've been going through some HTML5 video players but none of them seem to be supporting this kind of functionality. If anyone knows a (good) way to implement this feature please give me a hint.
Thanks in advance!

Even though this question has already been marked as answered, here's something that may interest you and anyone else who stumbles across here: Specifying playback range.
It's part of the Media Fragment API and currently works in the latest versions of Firefox, Chrome and Safari 6+.

You can implement it there is a Player.Play() event in a players, whenever Play() called start a timer and call the Player.stop() on the specific time you want.

I got the same problem and I didn't found something that can solves this problem, what you can do is to implement your own controls and display the video with a canvas...
and if you are trying to implement this in IOS you will not be able to do it.

My thought would be to use custom controls, as I don't believe that functionality is available natively. All the functionality of html5 controls (play, pause, start at timestamp, etc.) can be called via javascript. In this case you are going to want to edit the currentTime variable.
So you may want to consider setting up your own slider, where the start of the slider represents your starting point, and the end your ending point. Set the video to not play on page load. Then on page load have a javascript function change the currentTime to your starting point. For stopping you could occasionally query the currentTime. I wouldn't use a timer as delays like slow loading could throw it off.

I am trying to implement a similar video in "Preview Mode". I am utilizing the methods stated above by adding an event listener and then pausing the video at a currentTime()=='x' postition. To prevent user from simply hitting play again, the currentTime listener wont allow playback past the 'x' time in the timeline so each time the user hits play, it is automatically instantly paused again. Furthermore, at time 'x' the video container will become hidden through CSS thus preventing interaction from the user with the video.

Related

Chrome: Wrong sound when changing the audio source for Audio element and MediaStreamAudioDestinationNode

I have a app where I play different code-generated sounds. I place these sounds in a AudioBufferSourceNode.
I allow the the user to choose what output device to play the sound through, so I use a MediaStreamAudioDestinationNode with its stream used as the source for an Audio Element. This way when the user chooses an audio output to play the sound to, I set the Sink Id of the Audio element to the requested audio output.
So I have AudioBufferSourceNode -> some Audio Graph (gain nodes, etc) -> MediaStreamAudioDestinationNode -> Audio element.
When I Play the first sound, it sound fine. But when I create a new source and connect it to the same MediaStreamAudioDestinationNode, the sound is played with the wrong pitch.
I created a Fiddle that shows the problem.
Is this a bug, or am I doing something wrong?
The problem was identified based on the OP Chrome Ticket.
It seems to come from the lack of sync between AudioElement and its source AudioNode (AudioBufferSourceNode, OscillatorNode, etc.) when you pause the source and play it back again.
The solution is to always call AudioElement.pause() and AudioElement.start() alongside your source stop and start.
https://jsfiddle.net/k1r7o0xj/3/
It's possible to dynamically change your graph layout by using .connect() and .disconnect(), even when audio is playing or sent through a stream (which could even be streamed over WebRTC).
I couldn't find a reference in the spec, so I'm pretty sure this is taken for granted.
For example, if you have two AudioBufferSourceNodes bufferSource1 and bufferSource2, and a MediaStreamAudioDestinationNode streamDestination:
bufferSource1.connect(streamDestination);
//do some other things here, and after some time, switch to bufferSource2:
//(streamDestination doesn't need to be explicitly specified here)
bufferSource1.disconnect(streamDestination);
bufferSource2.connect(streamDestination);
Example in action.
Edit 1:
Proper implementation:
According to the Editors Draft on the Audio Output API, it is planned/will be possible to choose a custom audio output device for the AudioContext as well (by means of new AudioContext({ sinkId: requestedSinkId });). I couldn't find any info on the progress, and even found a related discussion which the asker apparently read already. According to this and (many) other references, it doesn't seem te be an easy task, but it's planned for WA V1.
Edit:
That section has been removed from the API Draft, but you can still find it in an older version.
Current workaround:
I played around with your workaround (using a MediaStreamAudioDestinationNode and Audio object), and it seems to be related to nothing being connected. I modified my example to toggle a single buffer (similar to your example but with an AudioBufferSourceNode), and observed a similar frequency drop. However, when using a GainNode inbetween and setting it's gain.value to either 0 or 1, the frequency drops disappeared (this isn't gonna be the solution if you want to create and connect new AudioBuffers dynamically).

AS3: Recording sound as they are output/played

I understand how to record microphone input in AS3 from this doc.
Is it possible to record sound exactly as they are being output/played?
The reason is I applied some sound transform (via the global SoundMixer) to sounds that are currently playing; and I also want to record this sound data while it is being played.
I just saw this question, to clarify, I am not trying to record just all sounds on the user's computer (which is not possible). My flash app has a Youtube player in it (via their AS3 API), and it's playing some sounds. I applied transforms using SoundMixer.soundTransform, and I want to record what's being played when the user is playing it.
Thanks in advance.
Just a passing suggestion.. on my desktop it seems ABLE to record sound into Flash from a different tab playing Youtube (HTML5).. I don't know how it's doing that!!
I allow microphone here.. (none actually plugged in, and speaker out has in-ear headphones)
http://code.tutsplus.com/tutorials/create-a-useful-audio-recorder-app-in-actionscript-3--active-5836
PS: Anyone trying this must reduce Windows volume since anything above 10-20% is distorted audio into the Flash app.
And this HTML5 youtube trailer was recorded fine into the Wav file produced by Flash app above
http://www.youtube.com/watch?v=MVt32qoyhi0
So after a quick search it seems my Realtek Audio is classed as a Full-Duplex soundcard and also within its own control panel I have an option called "Multi-streaming" which is enabled/ticked. I think Full-Duplex is enough to do this though. Try options within your soundcard's own settings software. Don't know about your end-users. Some hardware will do it, some wont, there is no all-round solution outside of AIR (which makes desktop apps out of your AS3 code).

vimeo timecode inaccurate using AS3 API

I am using Vimeo's Flash API so that I can embed and read the timecode of a video using the playProgressHandler, pause it at certain times, pop a menu, and use buttons that trigger seekTo calls. Although everything works, the timecode is inaccurate to varying degrees. Anywhere from 1-2 seconds. I can tell this because:
1) If I play my video on Vimeo and pause it at 6:03 and do the same with it embedded in Flash the visuals do not match up. Flash is lagging behind a tad.
2) I did a test using the JavaScript API. My seekTo calls were consistently accurate. To seek to the same spot using the AS3 API I had to add 1.5 seconds. But even this isn't foolproof. Sometimes it works, but sometimes it's still off.
Any ideas what would account for this inaccuracy and how I might fix this problem? Yes, I can ditch the AS3 and use the JS version, but I'd prefer to just fix what I've already built.
(I also posted this on Vimeo's forum, but I'm following their "Limited support in API Forum" post which suggests to post here)
Unfortunately, there's not much we can do to fix this other than to recommend that you use our iframe embed.
It has to do with the way that we retrieve files from our CDN. Because Flash doesn't support byterange requests, we pass a parameter that returns part of the file starting at that position. The nature of how that works means it's always going to be imprecise.

interactive video with html5

I am new to actionScript programming. I know some html and I am currently learning html5. I need to do an interactive video by putting html content in a specific time of the video. I'll be more concise:
For example, I have a video that is 5 minutes long, let's suppose that from the second 3:50 to 4:00 I need to display two boxes over the video, each one representing one choice. If at 3:50 the video shows the possibility to the viewer to select among two paths (the video told the user to select among those paths for instance) the viewer will have the possibility to select one of the paths by clicking on one of the two boxes that will appear in that time interval. I know this needs to be made with the tag and with hyperlinks.
My question is How do I tell the html5 video player to display a canvas from the minute 3:50 to the minute 4:00 in which two hyperlinks will display??
Thanks for your attention I will appreciate very much your help. I need some kind of guidance because I have been looking for many days.
For your use case it seems you want to be able to control the video flow of the user through interactions that jump to different times in the video.
Using html5 video player to seek to a different time in a video (using currentTime) you could create a click event on a box that you lay on top of the video and set the time when you click that box, using:
// Jump 30 seconds into the video
var time = '30';
var video = document.createElement('video');
video.src = "video.mp4";
// Set the time
video.currentTime = time;
video.play();
You can check out how we created an interactive video authoring tool(open source) using html5 and JS and use that.
If you don't want to spend time coding an interactive video you should check out H5Ps authoring tool through this simple example. You can test out creating your own at H5P.org as well. The tool is completely free.
I may be wrong, but I believe that you mean javascript instead of actionscript. If that is the case then I would definitely check this out Video.JS.
When you reach the current time you trigger your method/function which adds whatever you want on top of the video.
var whereYouAt = myPlayer.currentTime();
However, if you DO mean actionscript then you are working with a flash player. Therefore I suggest you take a look at this Vimeo Player
currentTime:Number [read-only] Returns the current playback time of the video.

Flash/AS3 "Shutdown" or "close" event?

I am making a Flash puzzle game. When the user loads the game, it needs to ask whether to resume the game from the last state (if it exists). I have a serialization system in place, but I need to ensure that the loaded state is definitely the last state.
One solution is to save the state to a SharedObject every time the state changes (when the player makes a move). However, the game state sometimes includes a countdown, so I'd have to be constantly (or periodically) saving the state in order to retain it. I guess this is acceptable, but it seems kludgey.
Is there any event which is fired when the swf is closed? Or anyone else have another elegant solution to this?
(I'm not using AIR, but solutions requiring AIR are appreciated.)
Edit: Another important point is that I may not have control over the embedding HTML for the game, as it may be syndicated to many sites. So solutions involving javascript aren't ideal.
If your Flash is hosted on a HTML page, you can use the 'Window is closing' event notification to fire a message into your Flash object either using old-skool GetVariable() or new-stylee FlashCall() mechanisms.
Whether you'll actually be able to persist state before your Flash object is destroyed is another question... you could always do the (evil) 'Are you sure you want to close/navigate away from this window?' alert that some sites use.
Handling DOM Events in Flex
HTML 5 events
The on-close event sounds the right solution, but I wonder if you could 'split' your serialisation? i.e. save the full puzzle state on each move, but also have a secondary 'lightweight' state for your countdown (or anything similar) which could be updated each time the countdown changes.
That may be easier than trying to catch the close event and save before the page is destroyed (especially as browsers are not consistent in this area).
this one should help you