Playing quicktime files with pause points via Keynote (forward and backward) - iphone

I have a quicktime file (.mov) generated by Keynote. When played in quicktime, it pauses itself at dozens of pre-defined points waiting for user input. It is basically a slide show with transitions pre-rendered to video.
I want to wrap this in an iPhone app, but see no methods on an MPMoviePlayerController to do anything other than play, which does not pause at the pause points.
Also, I want to be able to play backwards to a prior stop point if the user taps elsewhere on the phone.
Is there a better library for this than MPMoviePlayerController or (deprecated?) UIMoviePlayerController? Or am I overlooking methods that would allow this?

If you think about what you're trying to do, this is actually a fairly complex task. What you're really asking for is the ability to hook up an arbitrary movie playing UI tied to unique gestures, based on the specifics of your movie. I don't think either of the classes in question is going to get you there.
The easiest solution here might be content-based: generate one quicktime movie per "group" of Keynote slides, where each group ends at a pause point, and then it should be pretty easy to interpret gestures to either advance to the next movie (or load it automatically when you reach the end of the last one), or return to the start of the currently playing movie.

Related

Starting a Sound at a specified position with CocosDenshion?

It's possible to do stuff like:
Reproduce a sound at a specified starting position
Reproduce a sound for a certain ammount of time
Using CocosDenshion ?
If so, how ?.
If not...i have any alternatives, like a different sound engine or a certain class in the SDK that would allow me to do both things ?
You can play positional audio with CocosDenshion. See this tutorial for example.
Of course you can also loop sounds, if that's what you meant by question #2. You can always schedule a timer and stop or (better) fade out the sound after a specified amount of time. Programming the timer is of course up to you.
As for an alternative I can highly recommend ObjectAL. It does everything CocosDenshion does and a few things more, plus its well documented and comes with an excellent demo app with examples for playing positional audio, looping sounds, using stereo channels with panning and fading sounds.
If you don't want to fumble with including a static library in your project have a look at Kobold2D, it comes with ObjectAL (and Cocos2D) already setup and ready to use.

iOS frame by frame animation, by script

There are a few SO questions regarding frame by frame animation (such as frame by frame animation and other similar questions), however I feel mine is different so here goes.
This is partially a design question from someone with very little ios experience.
I'm not sure "frame by frame" is the correct description of what I want to do so let me describe that. Basically, I have a "script" of an animated movie and I'd like to play this script.
This script is a json file which describes a set of scenes. In each scene there are a few elements such as a background image, a list of actors with their positions and a background sound clip. Further, for each actor and background there's an image file that represents it. (it's a bit more complex - each actor has a "behavior" such as how it blinks, how he talks etc). So my job is to follow the given script referencing actors and background and with every frame, place the actors in their designated position, draw the correct background and play the sound file.
The movie may be paused, scrubbed forward or backward similar to youtube's movie player functionality.
Most of the questions I've seen which refer to frame-by-frame animation have different requirements than I do (I'll list some more requirements later). They usually suggest to use animationImages property of a UIImageView. This is fine for animating a button or a checkbox but they all assume there's a short and predefined set of images that need to be played.
If I were to go with animationImages I'd have to pre-create all the images up front and my pure guess is that it won't scale (think about 30fps for one minute, you get 60*30=1800 images. Plus the scrub and pause/play abilities seem challenging in this case).
So I'm looking for the right way to do this. My instinct, and I'm learning more as I go, is that there are probably three or four main ways to achieve this.
By using Core Animations and defining "keypoints" and animated transitions b/w those keypoints. For example if an actor needs to be at point A at time t1 and point B at time t2 then all I need to do it animate what's in between. I've done something similar in ActionScript in the past and it was nice but was particularly challenging to implement the scrub action and keep everytyhing in sync so I'm not a big fan of the approach. Imagine that you have to implement a pause in the middle of an animation or scrub to a middle of an animation. It's doable but not pleasant.
Set a timer for, say 30 times a second and on every tick consult the model (the model is the script json file along with the description of the actors and the backgrounds) and draw what needs to be drawn at this time. Use Quartz 2D's API and drawRect. This is probably the simple approach and but I don't have enough experience to tell how well it's going to work on different devices, probably CPU wise, it all depends on the amount of calculations I need to make on each tick and the amount of effort it takes ios to draw everything. I don't have a hunch.
Similar to 2, but use OpenGL to draw. I prefer 2 b/c the API is easier but perhaps resource wise OpenGL is more suitable.
Use a game framework such as cocos2d which I'd never used before but seems to be solving more or less similar problems. They seem to have a nice API so I'd be happy if I could find all my requirements answered by them.
Atop of the requirements I'd just described (play a movie given it's "script" file and a description of the actors, backgrounds and sounds), there's another set of requirements -
The movie needs to be played in full screen mode or partial screen mode (where the rest of the screen is dedicated to other controls)
I'm starting with the iphone by naturally an ipad should follow.
I'd like to be able to create a thumbnail of this movie for local phone use (display it in a gallery in my application). The thumbnail may just be the first frame of the movie.
I want to be able to "export" the result as a movie, something that could be easily uploaded to youtube or facebook.
So the big question here is whether any of the suggested 1-4 implementations I have in mind (or others you might suggest) can somehow export such a movie.
If all four fail on the movie export task then I have an alternative in mind. The alternative is to use a server which runs ffmpeg and which accept a bundle of all the movie images (I'd have to draw them in the phone and upload them to the sever by their sequence) and then the server would compile all the images with their soundtrack to a single movie.
Obviously to keep things simple I'd prefer to do this server-less, i.e. be able to export the movie from the iphone but if that's too much to ask then the last requirement would be to at least be able to export the set of all images (keyframes in the movie) so I can bundle them and upload to a server.
The length of the movie is supposed to be a one or two minutes. I hope the question wasn't too long and that it's clear...
Thanks!
well written question. for your video export needs check out AVFoundation (available as of iOS 4). If I were going to implement this, I'd try #1 or #4. I think #1 might be the quickest to just try out, but that's probably because I don't have any experience with cocos2d. I think you will be able to pause and scrub CoreAnimation: check out the CAMediaTiming protocol it adopts.
Ran, you do have a number of options. You are not going to find a "complete solution" but it will be possible to make use of existing libraries in order to skip a bunch of implementation and performance issues. You can of course try to build this whole thing in OpenGL, but my advice is that you go with another approach. What I suggest is that you render the entire "video" frame by frame on the device based on your json settings. That basically comes down to setting up your scene elements and then determining the positions of each element for times [0, 1, 2] where each number indicates a frame at some framerate (15, 20, or 24 FPS would be more than enough). First off, please have a look at my library for non-trivial iOS animations, in it you will find a class named AVOfflineComposition that does the "comp items and save to a file on disk" step. Obviously, this class does not do everything you need, but it is a good starting point for the basic logic of creating a comp of N elements and writing the results out to a video file. The point of creating a comp is that all of your code that reads settings and places objects at a specific spot in the comp can be run in an offline mode and the result you get at the end is a video file. Compare this to all the details involved with maintaining all theses elements in memory and then going forward more quickly or slowly depending on how quickly everything is running.
The next step will be to create 1 audio file that is the length that the "movie" of all the comped frames and have it include any sounds at specific times. This basically means mixing the audio at runtime and saving the results to an output file so that the results are easy to play with AVAudioPlayer. You can have a look at some very simple PCM mixer code that I wrote for this type of thing. But, you might want to consider a more complete audio engine like theamazingaudioengine.
Once you have an audio file and a movie file, these can be played together and kept in sync quite easily using the AVAnimatorMedia class. Take a look at this AVSync example for source code that shows a tightly synced example of playing a video and showing a movie.
Your last requirement can be implemented with the AVAssetWriterConvertFromMaxvid class, it implements logic that will read a .mvid movie file and write it as a h.264 encoded video using the h.264 encoder hardware on the iPhone or iPad. With this code, you will not need to write a ffmpeg based server module. Also, that would not work anyway because it would take too long to upload all the uncompressed video to your server. You need to compress the video to h.264 before it can be uploaded or emailed from the app.

iPhone Smooth Transition from One Video To Another

I have to figure out the best way to transition from one video to the next
BASIC IDEA: An example would be that there is a video of a person walking.....the user taps the video and a seamless transition occurs to a video of a person running (over simplified example)
My first thought was to create 2 movie players and use transitions between the 2 view elements. But movie-player doesn't support that.
stopping the current video, loading new content, and then starting it is a solution but not very elegant. We are making a interactive sales tool for our reps and we want this to look as professional as possible.
CURRENT THOUGHT: If there was some sample code for AVPlayer, it would seem I could use AVVideoComposition to switch between videos? But details on how that might happen don't seem to be currently available.
POSSIBLE CLUE: I figured this would be easy as I bought an app called Live Cams HD that shows 16 different video feeds at once.
Any ideas? Thanks in advance!
Steve, the short answer is that you are not going to be able to get the kind of results you want using AVPlayer. The h.264 video logic included in iOS is really great at playing video and video/audio together, but it really sucks at starting/stopping and switching from one clip to another. The reason is that there is a lot of buffering that needs to happen to load up and start playing a h.264 video in hardware. Basically, you need to roll your own code that sets UIImage/CGImageRef for your views in a way that makes it easy to switch from one clip to another by simply switching from one array of UIImage objects to another. Of course, that is easy to say yet not so easy to implement.
What I would suggest is that you evaluate existing code that already implements this logic instead of rolling your own. For example, have a look at this StreetFighter demo app. It shows how a very simple game like iPhone UI can be constructed using a series of clips that show a character doing a kick, a punch, or throwing a fireball. The results looks like this:
I also wrote up a blog post about seamless-video-looping-on-ios. You can of course roll your own code to do all this, but I would suggest reading more about my library at the linked website as it will save you a lot of time.
After the first video has played every frame except the last one, you quickly swap to a view with an image of the last frame (basically the last frame) and then you transition into a view with the an image of the first frame of the next video and start up that one.
Or you could create a animation with all your frames (programming your videos), that will make it customizable, but the quality will probably not be as good and the cpu usage can spike, so you will have to make a call on that one.

Open video in iPhone without controls

I am trying to play video without showing controls (volume and other buttons) but it also should be possible to make them visible by taping on the video.
The code is:
theMovie.scalingMode = MPMovieScalingModeAspectFill;
theMovie.movieControlMode = MPMovieControlModeDefault;
In this case it shows the controls by default and by taping on the video they get hidden.
If I change the mode to MPMovieControlModeHidden then I can not see the controls but also I can not bring them back.
Is there a way to start video without controls but not disabling them completely?
Good news Dmitriy!
I've found a solution that will do the job for you, I hope.
It is as follows:
Initialize your
MPMoviePlayerController object's
movieControlMode property with
MPMovieControlModeHidden value
Play the movie
After the movie playback has started set your MPMoviePlayerController object's movieControlMode property back to MPMovieControlModeDefault
Third step can be accomplished by observing MPMoviePlayerContentPreloadDidFinishNotification notification. Though this might cause unresponsive black screen (or of another color you've set as your MPMoviePlayerController object's backgroundColor) in case you will play a streaming video, which be actually preloaded by MPMoviePlayerController. I don't have any movie of compatible format on a remote server at my disposal right now so I can't test this scenario is real and therefore mess around to see if there's something that can be done to avoid this side effect (though I think I will do that if you publish or find such movie for testing somewhere in the Internet).
Tip: look at the bold piece of text if you don't want to know my long story about how boring I am actually starting to look into a problem by reading the documentation and looking into the sample code it offers.
You question has interested me so I started from looking at MPMoviePlayerController Class Reference on iPhone Dev Center. I didn't actually find anything related to the problem you've stumbled upon so I've decided to play around with this sample project MPMoviePlayerController reference - MoviePlayer. I juts wanted to reproduce your situation and maybe try dealing with it by simulating a single touch event or triggering the same method that responds to this event manually.
But it turned out that Apple's sample project in fact behaves absolutely like you want your's to. It starts video playback and the overlay controls are automagically animated out of the screen from the very beginning. I've looked through the code, it's rather simple and doesn't really 'deal' in any way with this problem you have. So maybe it's something you do (or do in somewhat not right order) that causes the problem. Check it out and get back to us with a cure because judging by usefulness metric there are people who have similar problems.

Any good iPhone sound manager framework?

I'm developing an iPhone game and currently using AVAudioPlayer for playing background music and sounds.
From what I've been reading, I'm not sure if that's the best way, but other alternatives seem to be overly complex.
Is there any good open source framework that works on the iPhone and I can integrate? I only need to control the volume and trigger sounds based on different game events.
Clarification: AVAudioPlayer meets my needs for playing one sound, but I'd like a wrapper class where I can set up multiple sounds and have them play based on some key.
It's not clear from your message whether AVAudioPlayer meets your needs. On the one hand you didn't mention any shortcomings you've encountered, but on the other hand your asking for alternatives suggests there are some.
If AVAudioPlayer does meet your needs, why make life difficult?
If AVAudioPlayer does not meet your needs, you need to explain what else you need before anyone can do anything but guess at what you're looking for.
The sound engine that Apple includes in their moon lander sample code application allows for playing multiple sounds at a time and everything.
You can use AVAudioPlayer. Each of your sounds will be a different instance of that class. Hold onto all the sounds (players) in a dictionary or an array. You can then easily play each by indexing off the array or getting with a key from the dict. Each sound can have it's own volume, or you can iterate the array or dict to set all volumes to whatever levels you like.
Couple of points to remember: 1. if you have to play the sounds in a timely manner, then use the -prepareToPlay method right after loading from file. 2. if you stop a sound, then -prepareToPlay is undone. If you pause a sound, then before you play it again, make sure you set the currentTime property to 0 so the sound starts from the beginning.