We're using AVPlayer in an app to do some playback of some embedded videos and need to implement a UISlider for the volume. What's a good way to read the current volume and set the current volume for this playback?
Note, I'm trying to link this to the system sound.
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 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.
I am writing an iPad app that uses the "Flite" text-to-speech engine to announce specific events. The Flite engine uses an AVAudioPlayer instance to play the speech audio once it renders. For fun, I decided to add some simple controls to my app to allow the user to control iPod playback (next, prev, play/pause and volume - the basics) while my app is running using MPMusicPlayerController (of course).
The problem I am having is that when I adjust the iPod volume using MPMusicPlayerController, all of my audio is affected, including other sound effects and the speech audio. I set the volume for these other audio players (AVAudioPlayer instances) to 1.0 before playing the sound but it seems that the volume is always capped at whatever the iPod player volume is set to...
Is this normal? And what can I do to get around it? I want my app's audio to play at system full volume regardless of the volume level of the iPod player. (Example: The user had set the system volume to 80% of the device's max. I want my app to play audio at 100% of that 80% while allowing the user to adjust the iPod audio playback to 0-100% of that 80%.) Note: I am not interested in "ducking" but setting the iPod volume lower at all times while my app is running (background music).
I also have the problem, that -sometimes- when you first launch the app and press play on the iPod player (which sends the [player play] call), the iPod does not respond. If I press the home button, go into the iPod app and start playback then, once returning to my app, it works fine. What the deal with that?
Thanks in advance for any help!!
It could be something to do with the audio session category you've specified. Check out the Audio Session Programming Guide to see if you've chosen the right category.
The volume buttons on the side control the system volume and by extension the volume of your app's sounds.
I guess it's considered to be the Master volume control.
you can set the volume for specific samples or sounds using the AVItem's setVolume
[item setVolume]
You can create an AVItem to reference an existing sound file in your application or on the iphone. The code is pretty simple and looks like this -->
AVItem *item [[AVItem alloc]
initWithPath:#"the file"];
[item setVolume];
btw, this will not affect the rest of the audio channel (instantiated by some kinda AVController object) and the volume that you've set in your code will not be displayed on you screen so im not sure if you can change it at run time.
I am trying to figure out how to adjust the volume of a movie played with MPMoviePlayerController on the iPhone without using the slider or the volume buttons on the side of the phone. Is it even possible to do this with code in a Apple approved way? I haven't been able to find anything in the APIs that relate to changing or setting the volume during movie playback.
I know a similar question was asked a little over a year ago (Is there a way to adjust volume in MPMoviePlayer Controller by program?), but I wanted to know if anyone had found a way to change the volume in MPMoviePlayerController since then.
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.