tags:

views:

436

answers:

6

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

A: 

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.

Soviut
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 ??
you should add this information to the question
Rhythmic Fistman
+1  A: 

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.

sliver
Referring to you addition: This is possible since revision 3.0 (AFAIK) of the iOS - one file will be played using hardware decoding, the second/additional one will be decoded on a software codec.
Till
+1  A: 

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.

Madhup
A: 

As far as I know, you can't play AVAudioPlayer and MPMoviePlayer at the same time.

mahboudz
+1  A: 

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];
apalankat
A: 

See example 2 and example 4 here:

http://www.modejong.com/iPhone/

You will want to mix the audio streams before hand, then play the resulting mix with an AVAudioPlayer. You can create an animation that will sync to the audio and then export as frames from Quicktime. Then import those PNG images into the animator described in example 2 and you will have a quick and dirty audio/video sync impl.

MoDJ