In my project, I have a video playing silently as a background video as an introduction. However, when I add the video to my project using NSURL I get this error (see screenshot). I have also provided the code below too. Any ideas?
let videoURL: NSURL = NSBundle.mainBundle().URLForResource("Background_2", withExtension: "mp4")!
I had this problem myself. I would suggest using a video encoder (Adobe Media Encoder CC is good). In the media encoder change, the video codec to H.264 and make sure it has a file extension of QuickTime .mov this will ensure Xcode and your application can read your video correctly.
In addition, when you have successfully changed the codec, make sure you add the video to your Bundle Resources!
Good luck!
Related
I have created a function which generates avcompostion according to AVAsset duration and content.
If the video is slow-mo or regular it works completely fine but when videoType is time-lapse it shows black screen after exporting.
If I played AVAsset on avplayer it shows perfect time-lapse. Problem only occurs while exporting.
I am using AVfoundation framework to get video camera frames at real time and then modifying those frames using one algorithm(which gives new modified image).
now I want all modified frames to be save as a video to iPhone library. I found a way to save video for input(original) frames using AVCaptureMovieFileOutput but not for modified frames.
Is there any way to save modified frames to iPhone Library as a video ??
UISaveVideoAtPathToSavedPhotosAlbum
Adds the movie at the specified path to the user’s Camera Roll album.
I'm recording audio separately from building an MPEG4 video on an iphone app. I'm trying to combine these using AVAssetExportSession.
Audio session is using 1 channel, kAudioFormatAppleLossless and AVAudioQualityMax. The video is AVVideoCodecH264, using pixel format type kCVPixelFormatType_32ARGB. This video without audio plays fine on my iphone via the photo library.
The exporter is telling me these are the supported presets, I'm using AVAssetExportPresetHighestQuality:
(
AVAssetExportPresetAppleM4A,
AVAssetExportPresetLowQuality,
AVAssetExportPresetHighestQuality,
AVAssetExportPreset640x480,
AVAssetExportPresetMediumQuality
)
and it's telling me this is the supported file type:
(
"com.apple.quicktime-movie"
)
if I switch to AVAssetExportPresetPassthrough I get file types of
(
"com.apple.quicktime-movie",
"com.apple.m4a-audio",
"public.mpeg-4",
"com.apple.m4v-video",
"public.3gpp",
"org.3gpp.adaptive-multi-rate-audio",
"com.microsoft.waveform-audio",
"public.aiff-audio",
"public.aifc-audio"
)
I have tried quicktime movie and mpeg 4 as outputFileType and still get the same results.
EDIT: May 10th
Crash was due to a pretty silly error. I have audio and video now ... sweet!
Key is .mp4 extension, exportSession setOutputFileType:AVFileTypeQuickTimeMovie, presetName:AVAssetExportPresetPassthrough
My crash was a simple issue. The bigger problem I had was using the wrong filename extension. I'm now using .mp4, AVFileTypeQuickTimeMovie and AVAssetExportPresetPassthrough.
I want to play a movie in my app and the video is stored in my ipad library.
Can anyone provide me the necessary guidance for it?
Get the MPMediaItem of the video you want using MPMediaQuery
Get the Asset URL like this:
NSURL *videoURL = [mediaItem valueForProperty:MPMediaItemPropertyAssetURL];
Instantiate an MPMoviePlayerViewController using videoURL as the content URL.
If the video is stored in your App's bundle then do this to get the URL:
NSURL *videoURL = [[NSBundle mainBundle] URLForResource:#"nameoffile" withExtension:#"mp4"];
See a sample of a custom view/viewController combo in Pragmatic iPad Programming. Check the source code for chapter 8 (free download from that page). They use a video provided as a file inside the project. Btw, if the file in the video appears red in XCode, you'll have to remove it and re add it, I think the project definition is a bit screwed.
HI all
i am playing a video(.mp4 format) without sound (i mean it doesn't have sound it is a mute video ) and in the background i am playing an audio file (.mp3 format) when i play my code through simulator it works fine as i want like when i tap on the video it is just mute but behind i am playing the audio so for user it seems that video has this sound but when i installed my code in device and play video than it doesn't work like so it play video but without sound than how can i play an audio and a video together in the above format ?
actually we are not just playing a single video or audio file it just comes from an array by choosing randomly and same for the audio file so we cann't do this i think so any other idea for it ??
Should we use another format for audio aur video for doing this thing ??
thanks for the help
Balraj verma
The problem is that the default Audio Session does not allow audio mixing.
In the Reference Library (Working with Movie Players) they say you should use a mixable category configuration for your audio session, for example the Ambient category. In the Application Delegate:
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
NSError *setCategoryError = nil;
[audioSession setCategory:AVAudioSessionCategoryAmbient error: &setCategoryError];
Apple's documentation states that some audio formats are not suited to be played back simultaneously because of hardware restrictions. See Playing Multiple Sounds Simultaneously for more details.
A solution for you would be to use PCM encoded audio which should allow simultaneous playback.
I would like to add that I managed to play two mp3 audio files at the same time on 3G and 3GS iPhones. Which shouldn't be possible according to documentation but worked for me.
You can rather use the an instance of AvAudioPlayer in a new thread. Use the following link to see how does this work
http://www.mobileorchard.com/easy-audio-playback-with-avaudioplayer/
create an instance of MPMoviePlayer to start playback of videos.
Hope this will work.
You should combine the audio and video using some video editing software like iMovie or Windows Movie Maker. Using the software to "composite" audio and video together is not a good idea and adds additional overhead, synchronization issues, etc.
As far as I know, you can't play AVAudioPlayer and MPMoviePlayer at the same time.