HTML Video plays with sound only through earphones -iOS? - iphone

I have developed a sencha-phonegap application which comprise of playing videos already present in the application.
When I play any other video such as a video song through the native player, audio is heard perfectly from the stereo speakers present at the bottom.
I am simply using the xtype: video tag to play the video. Here's my code to play the video:
{
xtype : 'video',
x : 0,
y : 0,
left :'0px',
top :'0px',
width : 175px,
height : 98px,
url : "path of video"
posterUrl: 'placeholder.png'
}
The problem which I am facing is that whenever the video is played, it only plays with sound when the earphones are connected and sometimes the audio can also be heard from the top-speaker (the speaker used during calls).
I have checked for the ringer and volume controls. Everything is at maximum.
My app supports iOS versions 5.0 and above.
Could this be iOS related issue?
Kindly provide some direction.
Thanx

Please first add Audio Toolbox and AVFoundation frameworks if not added already and than import class in which you add the below lines on app launch
#import<AVFoundation/AVFoundation.h>
than add these two lines in your project when you app launches
UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute,sizeof (audioRouteOverride),&audioRouteOverride);
May be it will work now.

On one of sencha forum, I found This Link Which Helped Me.
Since, it only specifically mentions about ringer off scenario, it also mentions in generic way that we need to add playback method for sound to work.
Cheers |m|

Related

Setting allows airplay to no still sends sound over airplay

I am working with a media player, some media does not have the right to be played over Airplay, don't ask why :). So when I get that media, I set
movieplayerController.allowsAirplay = NO;
If you were playing with airplay before, it is then on by default next time. By doing the code above, you will get the movie playing on your device, but the sound audio route is still sent over airplay. I have tried to overwrite the audio route, but it doesn't budge, seems like Airplay trumps all.
If I could just disable airplay, my problem would be solved, but I can't find anywhere a way to do that.
This looks similar to this question. The answer mentions that the AirPlay button should always be visible to send audio.

MPMoviePlayerController and AVAudioPlayer audio mixing glitch

I'm developing an interactive storybook type application for the iPhone and I've recently encountered a frustrating bug concerning audio mixing on the device.
Firstly, I setup an audio session. I set the category to AVAudioSessionCategoryAmbient and then init and play my AVAudioPlayer instance. Now, in the background whilst the audio is playing I'm pre-loading a video to play using an MPMoviePlayerController followed by a call to prepareToPlay. The reason I pre-load the video this way is because I need it to play instantly later on cue with fairly strict timing.
In this configuration, the audio/movie works fine and they mix and do not interrupt each other. However, this particular audio session category does not permit audio to continue playing while the device is locked, a feature I really need. As a result I'm forced to consider a different category: AVAudioSessionCategoryPlayback.
By default this category does not permit mixing with other audio, according to the Apple docs. To enable mixing with other audio I am overriding the relevant category:
OSStatus propertySetError = 0;
UInt32 setProperty = 1;
propertySetError = AudioSessionSetProperty(kAudioSessionProperty_OverrideCategoryMixWithOthers, sizeof(setProperty), &setProperty);
assert(propertySetError == 0);
Unfortunately, this solves my playing whilst locked issue but introduces another issue: the AVAudioPlayer audio is interrupted briefly as the video loads with a minor stutter. The stutter is small, perhaps less than a second but is enough to disrupt the user experience. I've read this related post which enabled me to pre-load the video with the AVAudioSessionCategoryAmbient, but unfortunately the same approach doesn't seem to work with the new category.
The audio session category is applied successfully, according to the return code. Does anyone know why enabling audio mixing with this category is not the same as the mixing facility provided by ambient category?
The best way I've found working a similar problem is to use the newer AVPlayer (+1 #adam) and set your app to enable background audio and receive remote control notifications. I was tipped off to this by #MarquelV following How can you play music from the iPod app while still receiving remote control events in your app?
If you can get backgrounding working properly, that should enable you to continue playing while the device is locked. Oh, and don't forget to add keys to info.plist, its easy to do and then have no idea why it isn't working.

iPod mini controls disabled when certain audio session parameters are set

I'm working on a music visualizer for the iPhone/iPad, under iOS 3 you could double-tap the home button and get iPod controls. With the latest version 4.1-4.2, these controls are now grayed out when the home button is pressed. I found a similar complaint at http://openradar.appspot.com/8696944, although there wasn't a solution.
I have the base sound category set to kAudioSessionCategory_PlayAndRecord, with kAudioSessionProperty_OverrideCategoryMixWithOthers set to true. (Just to add more fun to the problem I'm using OpenAL for some sound effects.)
I have tried setting the category back to ambient when the application goes into the background. but either it happens too late or it's not sufficient.
Here's where I've got to so far:
AudioSessionInitialize(NULL, NULL, NULL, self);
UInt32 sessionCategory = kAudioSessionCategory_AmbientSound;
AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(sessionCategory), &sessionCategory);
devicetwo = alcOpenDevice(NULL);
contexttwo = alcCreateContext(devicetwo, 0);
//The following two lines are the lines that gray out iPod controls:
alcMakeContextCurrent(contexttwo);
AudioSessionSetActive(YES);
The iPod controls remain grayed out even once the app quits... And removing the two culprit lines of code result in no sound being produced in the app.
Well I've given up.. I'm now coding my own UI based off of the AddMusic example code
http://developer.apple.com/library/ios/#samplecode/AddMusic/Introduction/Intro.html%23//apple_ref/doc/uid/DTS40008845-Intro-DontLinkElementID_2
I'm happy to report that play and stop via the MPMusicPlayerController doesn't seem to conflict with the play and record session settings. And building your own play/pause/FF seems to be fairly straightforward
p.s. I've also discovered that this Music Visualizer app: http://itunes.apple.com/us/app/music-visualizer/id337651694?mt=8 is just this addMusic sample uploaded and this guy is charging 2 bucks for it.. It's got awful reviews.. but it still seems wrong that it's on the app store.
My iPod touch 4G is running iOS 4.2, and it doesn't have this problem. I would attempt to contact Apple.

iPhone Playing a sound clip while recording a video using UIImagePickerController ... possible?

I'm using openAL to play sounds. I have a view controller that lets users upload a video. I want to give them a 1 minute warning sound so that they know to wrap things up. I tried using a call to SoundEngine_StartEffect(warningSound); but it just doesn't play anything. Is there a work around to this?
Did you try to set mix with others?
UInt32 doSetProperty = 1;
AudioSessionSetProperty(kAudioSessionProperty_OverrideCategoryMixWithOthers, sizeof(UInt32), &doSetProperty);
It is in most cases a "must have", when trying to record and play at the same time.

how can we play audio and video together in ipod/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.