how to play audio as background in blackberry - blackberry

I have created Player object as
player = Manager.createPlayer(inputStream,"audio/mpeg");
and plays the audio as
player.realize(); player.prefetch(); player.start();
It starts playing the stream. Here the inputstream refers live streaming url. Now my question is when i click on the back button the application will be closed so that player also will stop the playing. but I need to play the audio in background even the application is closed and after launching the app i dont want to initialize the Player object again,for this i have to maintain the Player object as singleton. I am using 4.7 blackberry api.Can someone please tell me how all these will possible?
thanks
venu

Override the "onClose()" method in your Screen class to catch the close event and put your app in the background:
public boolean onClose() {
Application.getApplication().requestBackground();
return false;
}

Take a look at the multi-part blog post by Tim Windsor from RIM on running applications in the background.
Part 1
Part 2
Part 3
Part 4

Basically you need to override the behaviour of the back button and just send your app to background without closing it.Then the player will continue to play. There are many resources and tutorials on this. Maybe something from the links #Ted Hopp posted might help you.

Related

My music player is stop play music when i load my application

I am doing alarm based application in which my application is being prevent from deep sleep and fire local notification when time is comes up.For Prevent deep sleep i am using the mmpdeepsleeppreventer but it raise one problem in my application.When any one play music in music player and start my application then music player stop play music.How can i over come from this?
This is because audio session initialization in MMPDeepSleepPreventer.m in - (void)mmp_setUpAudioSession it uses audio session category kAudioSessionCategory_MediaPlayback.
Look for this Apple docs:
https://developer.apple.com/library/prerelease/ios/documentation/AudioToolbox/Reference/AudioSessionServicesReference/index.html
"This category normally prevents audio from other apps from mixing with your app's audio. To allow mixing for this category, use the kAudioSessionProperty_OverrideCategoryMixWithOthers property."
Try to set audion session property kAudioSessionProperty_OverrideCategoryMixWithOthers

How to mute VLCMediaPlayer

I placed 2 VLCMediaPlayer in the IPad ViewController.
Then I want to mute one of the players.
I executed the following code from VLCAudio class:
[VLCMediaPlayer.audio setMute:YES];
But the voice of the player was still on.
Then I added another piece of code:
[VLCMediaPlayer.audio setVolume:0];
Nothing had been changed.
Is it because both setMute and setVolue functions don’t work under the ISO VLCKit?
If so, how to mute VLCMediaPlayer by coding?
Set the current audio track to -1. Performance-wise, this is more efficient, too, since the audio information isn't even decoded.
Volume control (incl. mute) isn't supported with current versions of MobileVLCKit on iOS, but on the Mac only.
If you want to mute from the beginning, I found a way to do it.
Before you send play msg to the player instance, you should init it with options, such as
self.player = [[VLCMediaPlayer alloc] initWithOptions:#[#"--gain=0"]];
where "--gain=0" which means audio gain set to 0. This is not the documentation method, may not work on every version of mobile vlc framework. But it works for me.
If you want to mute while playing, you can try
self.player.currentAudioTrackIndex = -1;
This also works for me!

Getting warning while recording " MP AVAudioSessionDelegateMediaPlayerOnly end interruption"

I have been recording video successfully in my app using AVAssetWriter for long time but today I start to see some strange warning comes when I stop recording,
Scenario:
I record the video & can record again the video multiple times [NO WARNINGS]
I play the video in MPMoviePlayerController [NO WARNINGS]
I record the video after playing the video and once I click stop recording I get the warning
Warning:
MP AVAudioSessionDelegateMediaPlayerOnly end interruption. Interruptor <RecorderServer> category <(null)> resumable <0>, _state = 0
Does anyone know what might be the issue or had similar issue like I have?
It feels like I have solved my problem, although it was not a big issue just a minor mistake which I did,when I play video in MPMoviePlayerController , after I finish playing video using the notification, i was not releasing the player object, I thought it would be enough to unregister from the notification but it helped when i set the self.player=nil;
Seems that your audio session category is set to kAudioSessionCategory_MediaPlayback when you play which is ok. Change it to a suitable category for recording.
Look the different available categories here http://developer.apple.com/library/ios/documentation/Audio/Conceptual/AudioSessionProgrammingGuide/AudioSessionCategories/AudioSessionCategories.html#//apple_ref/doc/uid/TP40007875-CH4-SW1

AVAudioSessionDelegate called at endInterruption, but beginInterruption not called

I'm setting up an AVAudioSession when the app launches and setting the delegate to the appDelegate. Everything seems to be working (playback, etc) except that beginInterruption on the delegate is not being called when the phone receives a call. When the call ends endInterruption is being called though.
The only thought I have is that the audio player code I'm using used to be based on AVAudioPlayer, but is now using AVPlayer. The callbacks for the AVAudioPlayer delegate for handling interrupts are still in there, but it seems odd that they would conflict in any way.
Looking at the header, in iOS6, it looks like AVAudioSessionDelegate is now deprecated.
Use AVAudioSessionInterruptionNotification instead in iOS6.
Update: That didn't work. I think there's a bug in the framework.
Yes, in my experience, beginInterruption, nor the newly documented AVAudioSessionInterruptionNotification work properly. What I had to do was track the status of the player using a local flag, then handle the endInterruption:withFlags: method in order to track recovery from interruptions.
With iOS 6, the resuming from an interruption will at least keep your AudioPlayer in the right place, so there was no need for me to store the last known play time of my AVAudioPlayer, I simply had to hit play.
Here's the solution that I came up with. It seems like iOS 6 kills your audio with a Media Reset if an AVPlayer stays resident too long. What ends up happening, is the AVPlayer plays, but no sound comes out. The rate on the AVPlayer is 1, but there's absolutely no sound. To add pain to the situation, there's no error on either the AVAudioSession setActive, nor the AVPlayer itself that indicates that there's a problem.
Add to the fact that you can't depend on appWillResignActive, because your app may already be in the background if you're depending on remote control gestures at all.
The final solution I implemented was to add a periodic observer on the AVPlayer, and record the last known time. When I receive the event that I've been given back control, I create a new AVPlayer, load it with the AVPlayerItem, and seekToTime to the proper time.
It's quite an annoying workaround, but at least it works, and avoids the periodic crashes that were happening.
I can confirm that using the C api, the interruption method is also not called when the interruption begins; only when it ends
(AudioSessionInitialize (nil, nil, interruptionListenerCallback, (__bridge void *)(self));
I've also filed a bug report with apple for the issue.
Edit: This is fixed in iOS 6.1 (but not iOS 6.0.1)
Just call:
[[AVAudioSession sharedInstance] setDelegate: self];
I just checked on my iPhone 5 (running iOS 6.0) by setting a breakpoint in the AudioSessionInterruptionListener callback function that was declared in AudioSessionInitialize(), and this interrupt callback does, in fact, get called when the app has an active audio session and audio unit and is interrupted with an incoming phone call (Xcode shows the app stopped at the breakpoint at the beginning of the interruption, which I then continue from).
I have the app then stop its audio unit and de-activate its audio session. Then, on the end interruption callback, the app re-activates the audio session and restarts the audio unit without problems (the app is recording audio properly afterwards).
I built a brand new audio streaming (AVPlayer) application atop iOS 6.0.x and found the same problem.
Delegates are now deprecated and we have to use notifications, that's great, however here's my findings:
During an incoming phone call I get only AVAudioSessionInterruptionTypeEnded in my handler, along with AVAudioSessionInterruptionOptionShouldResume. Audio session gets suspended automatically (audio fades) and I just need to resume playback of AVPlayer.
However when attempting to launch a game, such as CSR Racing, I oddly get the dreaded AVAudioSessionInterruptionTypeBegan but no sign when my application can resume playback, not even killing the game.
Now, this may depend on other factors, such as my audio category (in my case AVAudioSessionCategoryPlayback) and the mixing settings of both applications (kAudioSessionProperty_OverrideCategoryMixWithOthers), I'm not sure, but definitely I see something out of place.
Hopefully others reported that on 6.1beta this is fixed and I yet have to upgrade, so we'll see.

Get the name of a track the user is playing in iOS

As part of an iOS application we are trying to make, we would like a very small part of our application to keep running is the background, and save the names of the tracks the iPod is playing, and/or send them to our server.
So basically we want to register an event listener that tells our app when the iPod application plays a track, even if our app is in the background.
Is this possible? I have been digging around in the documentation and haven't found much useful.
Thanks!
You can get the current playing song and just add them to an array of string by getting the names
On iPhone: Find out what song is currently playing? (in the iPod music player)
EDIT: Better answer in this link
EDIT 2:
There's this link
http://www.iphonedevsdk.com/forum/iphone-sdk-development/45438-different-sound-volumes-mpmusicplayer-system-sounds.html
A bit down he talks about some methods which gets invoked on song changes
- (void)handleNowPlayingItemChanged:(id)notification {
MPMediaItem *currentItem = self.musicPlayer.nowPlayingItem;
self.songLabel.text = [currentItem valueForProperty:MPMediaItemPropertyTitle];
self.artistLabel.text = [currentItem valueForProperty:MPMediaItemPropertyArtist];
}
hope this helps.

Resources