Can I preload mp4 before play with MPMoviePlayerController? - iphone

Can I preload mp4 before play with MPMoviePlayerController ?
I have a local mp4 video. I fount it stop at the first frame little time. I'm sure it don't matter to network. Can it preload to memry before play with MPMoviePlayerController?

I'm assuming by "local" you mean "on a machine in the same room as you". And if that is true, then the short answer is: "Yes you can."
The way I would do this is to save (or cache) a copy of the movie file to your Documents or Cache directory on your iPhone and then when you create your MPMoviePlayerController object, you can refer to the file saved on the device (via a NSURL pointing to the file saved).
Take a look at Apple's documentation for MPMoviePlayerController's initWithContentURL: method (which I have linked for you).
If by "local" you mean the file is already on the device and it is inexplicably freezing, then there is likely another problem with the mp4 you are trying to play.

Related

How to play MP3 url in AVaudioPlayer without loading buffer

I'm trying to play in my app mp3 file from url ... But the problem is the file size is big 120 MB ... So i said why not making it load same as youtube since i heard we can control the buffer and not loading the full audio file to the player ... instead we can play small sizes same as youtube for example ... i search and tried to get a way or a code but i couldn't find anything.
So is it possible to play mp3 file using AVaudioPlayer immediately without loading the full audio file?
Not with AVAudioPlayer. Use AVPlayer instead.

Using a webview to play an mp3- is it possible to keep it playing even when the screen is locked?

I have a portion of my app that simply launches a webview linked to an mp3 file- it opens the file and plays the audio. What I'd like to do is allow that audio to continue playing even if the user locks their iPhone. (As a side note, is there any way to replace the default Quicktime logo that appears in the player? Not that big a deal, just thought I'd ask =)
A third question- I also do the same thing (webview) with an .m3u linked file to stream live audio throughout the week- is it also possible to keep it playing when the iPhone is locked?
Thanks!!
Ben
Quick Edit: The same URLs work great in IOS Safari (locking and unlocking doesn't affect the audio. Just not in my app's webviews.
I did find my answer though, in case anyone comes here looking. Easiest thing in the world too- just add a row to the plist file labeled "Required Background Modes" and under that set item 0's value to "App plays audio". Voila!
Since the audio is in a UIWebView, I don't believe that you'd be able to play it in the background.
EDIT: I was wrong, adding "App Plays Audio" to the UIBackgroundModes will make it work even when audio is in a UIWebView.
Have you thought about just streaming the .mp3 file yourself? Should be easy enough and you'd be able to setup background streaming. To get you started, I'd check out Matt Gallagher's AudioStreamer class which easily allows you to stream .mp3 files and other audio files from the net: https://github.com/mattgallagher/AudioStreamer

UIVideoEditorController canEditVideoAtPath returns false on assets from library

on assets from library i.e: assets-library://asset/asset.mov?id=0399CB6D-D3D9-4F4C-82B9-AC93CCE2FB16&ext=mov
[UIVideoEditorController canEditVideoAtPath:videoPath] returns always NO
i see this error in the console:
<Warning>: Video assets-library://asset/asset.mov?id=0399CB6D-D3D9-4F4C-82B9-AC93CCE2FB16&ext=mov cannot be saved to the saved photos album: Error Domain=NSOSStatusErrorDomain Code=2 "This movie could not be played." UserInfo=0x6f7b90 {NSLocalizedDescription=This movie could not be played.}
help?
apparently there is no way to edit library assets with UIVideoEditController.
i ended up copying the file using AVAssetWriter to the app sandbox and then i was able to use UIVideoEditController.
I am able to write video tracks successfully.I am able to save that file to gallery as well.Video gets played with all the quality of original file .But not able to copy audio bufers and hence video gets played without sound.
But if I try to write audio track first and then video track then the writing fails for video buffers .That is BOOL appended = [assetWriterInput appendSampleBuffer:buffer]; fails by returning NO .
Buffers get appended while writing audio track.Then I cancel reader for audio track and start wrting reading video track.Appending the video buffers fails.For both writtes I am setting startSessionAtSourceTime:KCMTimeZero .
If I write only video buffers then video gets played without audio.
I want to make it possible to copy that .MOV file present inside gallery with all audio+video tracks inside it.
***Purpoose : Finally I want to edit the file copied using UIVideoEditorController.We can not directly edit file inside gallery.Hence I am first copying it inside sandbox and then editing it.

Play audio and video at a same time in iPhone application

Is it possible to play audio and video file at a same time? I want to play different audio file and video file at a same time and also want control for both, so is it possible?
Sorry, not that I know of. The movie view automatically stops all audio files and takes up the whole screen, so you are forced to listen to the audio for the video.
If the audio is part of the video file, yes.
If it's an MP3 file or some other external type how are you planning on playing it? The phone might allow this to happen depending on what you're up too.
You might be in luck soon though...
Another helpful link is here.

How to debug a AVAudioPlayer play failure?

I'm using an AVAudioPlayer to play a mono AIFF file from my app's Documents directory.
On the simulator, [player play] returns YES and I hear the file playing. On the device the play method returns NO and nothing happens. I grabbed the file via the Organizer - it plays back fine on my Mac and seems to be well-formed. I realize the simulator can access codecs that aren't available on the iPhone, but that shouldn't matter in this case, should it?
I'm at a loss as to how to debug this. Any suggestions?
I asked this question on Apple's forum and someone there asked if I had activated an Audio Session. I hadn't, and doing so fixed my problem.
Make sure you do not use an absolute path to the audio file. When you move to device, the paths change. You need to get the path to the documents folder using the standard methods and then add the relative path to your audio file. That way you get a correct path regardless of the hardware or other changes.
Create a delegate to the audio player, and override -audioPlayerDecodeErrorDidOccur:error: to see if any error happens.