I am using AVPlayer for playing song from iPod Library. There are very limited methods in AVPlayer compare to AVAudioPlayer.
When I play song using AVPlayer in iPhone, the actual sound is very low compare to the song played in iPod Library.
My code goes as below:
AVPlayer *avPlayer = [[AVPlayer alloc] initWithURL:songURL];
[avPlayer play];
How can I amplify sound or increase volume while playing with AVPlayer??
Edit:
I had also gone through this question and tried the apple's link but there is no significant difference in sound. I tried passing volume in float as 0.8, 1.0, 2.0, 10.0, 100.0. But when i pass higher values then disturbance increases... and Volume does not increase.
What are the other ways to increase sound with AVPlayer??
Check out this link.
You cannot set volume greater than 1.0 for AVPlayer. If you increase volume to a value more than 1.0 then the distortion of voice and disturbance will increase.
But you need to check whats the output source of the player. Default is microphone, so try setting it to loudspeaker to get louder output.
Please refer below link for that.
How to record and play sound in iPhone app?
How to increase volume of sound recorded using AVAudioRecorder
Hope this help you.
Related
I have a AVPlayer playing mp3 in background and a MPMoviePlayer visible to user playing another mp3 I am able to set volume for MPMoviePlayer using
[[MPMusicPlayerController applicationMusicPlayer] setVolume:cObj_VolumeLevel];
But it is changing volume for both AVPlayer and MPMoviePlayer I want to control both separately
Just putting this as an answer instead of a comment...
MPMoviePlayerController setVolume sets the device's volume which will adjust the volume of anything coming out of the ios device. AVPlayer goes one step beyond this in being able to individually set volume for each of its players.
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.
The documentation for AVPlayer states the following:
[The] player works equally well with local and remote media files
However, the documentation for AVAudioPlayer states the following:
Apple recommends that you use this class for audio playback unless you are playing audio captured from a network stream
For the work I am doing I need some of the capabilities of AVAudioPlayer, but all my audio is being streamed. The main thing I need from AVAudioPlayer that AVPlayer does not have is the "playing" property. It is difficult to build a player UI without that property, among others.
So what is the difference between AVPlayer and AVAudioPlayer that makes the latter unsuitable for network streaming? Is there a way to get some of the info from AVPlayer that AVAudioPlayer provides such as the "playing" property?
AVPlayer can play from AVPlayerItem using AVURLAsset with an iPod library url. The AVAudioPlayer cannot play from an iPod library url.
AVPlayer has no volume property and requires the use of the system volume setting which can be controlled only by the hardware switch or an MPVolumeView. But you can set the mix volume of AVAudioPlayer.
AVPlayer seems to report an incorrect currentTime after seeking. But AVAudioPlayer reports accurately.
7 years after...
From a point of view with dependence on Swift and CocoaPods, so my answer is comparing for iOS 8+ only.
1. iPod library support
identical support since iOS6
2. volume control
identical support:
You can set the mix volume of AVAudioPlayer directly.
You can set the mix volume of AVPlayer with an AVAudioMix on the AVPlayerItem
3. seeking control
both AVPlayer and AVAudioPlayer seem to report an incorrect currentTime after seeking:
for AVAudioPlayer, it is suggested to stop() the AVAudioPlayer before seeking
for AVPlayer, it is suggested to pass the option AVURLAssetPreferPreciseDurationAndTimingKey when initializing AVURLAssets. And rely on values given by observer block.
4. changing source
you need only one AVPlayer to play multiple files
you need multiple AVAudioPlayer to play multiple files
The AVPlayer actually has a similar property as the playing property of AVAudioPlayer.
Take a look at the rate property.
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.
is there a way to adjust the speed of the playback of an audio while playing in Objective C for the iPhone/iPod touch?
Also would be interesting if playing a file backwards would be possible.
Thanks
Tom
AVAudioPlayer doesn't give you speed control, but it does let you set the position, so you could do a poor man's speed up/reverse the same way QuickTime Player does: by jumping through the file and playing small snippets at normal speed.
Or you decompress the samples yourself with an offline AudioQueue and do whatever rate you want. That's what I do.
A cheesy way to do it is to tweak the sample rate when you send it to the playback engine (Audio Queue, Remote I/O Unit, OpenAL). For PCM -- and I'm not sure this would work for anything other than PCM (so you'd have to decompress an MP3 or AAC with Audio Converter Services first) -- you could speed up your audio by adjusting the AudioStreamBasicDescription like this:
audioStreamDesc.mSampleRate = audioStreamDesc.mSampleRate * 1.2;
Note that this also changes the pitch of your audio: not only is it faster, it's also higher pitched. The Mac has a system-supplied audio unit that allows you to change playback speed without changing pitch, but it seems to be absent on iPhone.
As of iOS 6 (and I believe 5) you can adjust playback rate within AVAudioPlayer; no extra code necessary:
player = [[AVAudioPlayer alloc] initWithContentsOfURL:
[NSURL fileURLWithPath:path] error:&err];
player.enableRate=YES;
player.rate = 0.5;
[player play];
Rate can range between .5 and 2.0, and can be adjusted during playback as long as enableRate is set to YES before playback starts.