how can we play audio and video together in ipod/iphone? - iphone

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.

Related

How to play, record and edit the audio in iPhone

Here I need to develop an IOS app consists of record,play and edit the audio.I done the Audio Recording and Playing by using the AVAudioRecorder and AVAudioPlayer.
But I want how to edit the audio,and save it. Is there any way to do.kindly help me
Recording:
AVAudioRecorder *audioRecorder = [[AVAudioRecorder alloc]
initWithURL:audioFileURL
settings:audioSettings
error:nil];
[audioRecorder record];
Playing:
AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:audioFileURL error:nil];
[audioPlayer play
Here I have included the sample code for recording and palying the audio, but how can i edit the audio linke in this Yotube link: https://www.youtube.com/watch?v=LWz2x9dXpsM
Audio recording can be done using AVFoundation framework of apple but editing of audio is kinda difficult process. So I suggest you to do it using open source library projects in iOS.
You can use The Amazing Audio Engine which provides great quality of audio recording, Audio Filtering and Audio Mixing. The Amazing Audio is build in Non-ARC and is very light, thread safe.
You can also download the sample of Amazing Audio Engine from Github.
Check this link once.In this example how to play audio and how to record the audio using AVAudioplayer Framework.
http://www.appcoda.com/ios-avfoundation-framework-tutorial/
You can use Extended Audio File Services. have a look at the reference for ExtAudioFileRead & ExtAudioFileWrite (they have sample code) then you can open one audio file read it, trim it and then write the new one.Go here
Extended Audio File Services Reference

Recording only audio and a single snap during recording through AVCamCaptureManager in Objective C

I want to record audio for 10 seconds and take a snap when I stop recording the audio using AVCamCaptureManager in Objective C.
I gone through
AVCaptureSession specify resolution and quality of captured images obj-c iphone app
and implemented the same.
I am also using AVAudioSession to record audio when I start AVCamCaptureManager to take snap but it do not record audio its because AVCamCaptureManager also use the same audio device resource to record audio.
How can I do this? Please help..

Recording audio and playing iPod at the same time?

I am trying to be able to record audio through the iPhone's microphone while simultaneously playing music from the iPod.
The recording and playback work separately, but if I try to playback from the iPod and record at the same time the recording stops.
By the way, I am not actually recording the audio to save the sound file, but merely analyzing it. It's for my app that flashes to the beat of the music you play.
Does Apple just not allow record and playback at the same time?
You should be able to do this by setting the Audio Session to AVAudioSessionCategoryPlayAndRecord. Information on this is in the Apple docs, although admittedly the Core Audio documentation is (and has always been) lacking in clarity.
AVSession Class Reference
Also, it's worth noting that AVAudioRecorder and AVAudioPlayer automatically set the session for you. You can wrestle control and set the session manually using the key I highlighted above.
the problem may be you are recording audio to the same path where the playing file is saved.
try to play an audio from a url with AVAudioPlayer and you can record with AVAudioRecorder at the same time.
Cheers :) :)

How to increase volume of sound recorded using AVAudioRecorder

I am using the link mentioned below to record audio through my iPhone app:
How do I record audio on iPhone with AVAudioRecorder?
When I try to play my recordings using AVAudioPlayer on my device, I have seen that the sound volume of my recordings is very low even when my device volume is full.
Recording is working fine.
What can be done to increase the volume?
When recording audio, set the audio session to AVAudioSessionCategoryPlayAndRecord or just AVAudioSessionCategoryRecord. When you're done, set it back to just AVAudioSessionCategoryPlayback.
Solution for iOS 12 + Swift 5.0:
When starting recording use:
recordingSession.setCategory(.record) // recordingSession is of type AVAudioSession
When playing the record audio use:
recordingSession.setCategory(.playback)
Note: Place the statements into a do-catch block.
you can try AVaudioSession.sharedInstance().overrideOutputAudioPort(AVAudioSessionPortOverride.Speaker)
this is because your output device set to inbuilt speaker in iPhone.
while iTab have only speaker so no problem occurs.

iPhone SDK: how to play music and record from the mic at the same time?

I am trying to play music from the user's music library and at the same time record from the built-in microphone. However, as soon as I start recording from the microphone it automatically pauses the music, and I can't find any way to play music and record at the same time. I am using the MediaPlayer framework to play music and the AudioToolbox framework to record from the mic.
Does anyone know if it is possible to play music and record from the mic at the same time, and if so how to do it?
You set your audio session to kAudioSessionCategory_PlayAndRecord
and create an in/out remote io audio unit.
The "loopy" author talks about how to do this here and provides code.
The trailblazing tones of the article are slightly dated now.
You'll need to set your audiosession properties to allow both recording and playback. This might mean that you need to use AudioToolbox for the playback as well as the recording.
try:
Add #import "CDAudioManager.h"to AppDelegate.m and Add [CDAudioManager
initAsynchronously:kAMM_PlayAndRecord]; to - (void)
applicationDidFinishLaunching:(UIApplication*)application