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.
Related
I have a problem in playing audio file from URL in the background while the iPhone is locked.
my app plays podcasts, but while it is playing the podcast at specific second the podcast will stop and an ad will play, the ad consist of three audio tracks, first and last are the messages "please wait, ad will play" and "thanks, your track will complete now", and the middle track is the ad it self from URL.
I tried to make two AVPlayers one for track and the other for the ad, and I tried to make four players for each track, the process works well if the app is running, but when the iPhone is locked, just the first message starts, and nothing happen after.
any suggestions !!
Finally I found the solution of my problem,
When I save the ad file I use [file writeToFile: atomically:], but the app can't reach the document directory when the device locked for a long time unless the file is in the noneProtection mode, so I use [file writeToFile:filePath options:NSDataWritingFileProtectionNone error:nil];
It Works :)
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!
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
I am trying to receive information about the currently played track in a iOS app. This works pretty fine while the iPhone is not connected to an accessory. If I connect it to my car (Opel Astra, iPhone jack), the following code stops to work as described in the documentation:
If you create an iPod music player and the user plays an item from another library using Home Sharing, the value of this property is nil.
Code:
// nil while connected to an accessory
MPMediaItem *nowPlayingMediaItem =
[[MPMusicPlayerController iPodMusicPlayer] nowPlayingItem];
// Works while not connected to an accessory
NSString *title = [nowPlayingMediaItem valueForProperty:MPMediaItemPropertyTitle];
I even tried "hacky" stuff like to access "private" properties (original code):
MPMediaQuery *query=nil;
MPMediaItemCollection *collection=nil;
id internalPlayer=nil;
Ivar internalPlayeriVar = object_getInstanceVariable(iPod, "_internal", NULL);
internalPlayer = object_getIvar(iPod, internalPlayeriVar);
NSLog(#"internalPlayer: %#", internalPlayer);
Ivar queryIvar = object_getInstanceVariable(internalPlayer, "_query", NULL);
query = object_getIvar(internalPlayer, queryIvar); // nil everytime
Ivar collectionIvar = object_getInstanceVariable(internalPlayer,
"_itemCollection", NULL);
collection = object_getIvar(internalPlayer, collectionIvar); // nil everytime
or to call private methods:
// Same behaviour like [iPod nowPlayingItem], works
// only while no accessory is connected
MPMediaItem *nowPlayingMediaItem =
[iPod nowPlayingItemAtIndex:[iPod indexOfNowPlayingItem]];
// Works while not connected to an accessory
NSString *title = [nowPlayingMediaItem valueForProperty:MPMediaItemPropertyTitle];
Its also no solution to access the new MPNowPlayingInfoCenter, its nil all the time.
[MPNowPlayingInfoCenter defaultCenter].nowPlayingInfo
My car plays my music directly without using a iPhone app and it seems my iPhone knows what the car is currently playing because it displays the title, artist and cover icon on the lock screen (and only there). Also the internal play count gets increased.
If I check the playback state, it returns also YES if the car plays music:
[[MPMusicPlayerController iPodMusicPlayer] playbackState] == MPMusicPlaybackStatePlaying
So, is there any way (may be through calling private methods) to access the song, the car is currently playing?
Are you using threads? If so run the code on the main thread. If not then register for the MPMusicPlayerController notifications for item change. That way when the song changes your app will know what the new song is. Also be sure this runs on the main thread as well.
If your playback state is updating while connected but your nowPlayingItem isn't, this would confirm it is a bug. I would submit a bug report for this issue.
EDIT:
Visit https://developer.apple.com/support/resources/bug-reporting.html and scroll to the bottom. The last question says you can contact TSI for bug work arounds. You get 2 TSI requests for being a developer for free so you can use one of those to ask them if they have a work around using a private library until the bug is fixed.
Apple just "fixed that" in iOS 6.1 after I reported it as a bug. The following code now works while my iPhone is connected to my car:
MPMediaItem *nowPlayingMediaItem = [iPod nowPlayingItem];
NSString *title = [nowPlayingMediaItem valueForProperty:MPMediaItemPropertyTitle];
NSLog(#"Playing title: %#", title);
And, what I really like: It is also possible to change the playing track using the iPod app - the app appears as you expect it, instead of the big white "connected to an accessory" screen. So this may also work programatically.
I am pretty sure the answer is no, you can't with any public api's at least but you should file a bug with apple for two reasons:
The reason MPNowPlayingInfoCenter does not give you the info is because it has to be specifically implemented by the app playing the music, if apple's app playing then it should have been implemented so file a bug.
Now if you say [[MPMusicPlayerController iPodMusicPlayer] playbackState] reflects playback changes then that would mean iPodMusicPlayer is still the app in charge of playback so giving you nil for MPMediaItemPropertyTitle should also be reported to apple as a bug.
Additionally non public information on the topic is likely covered by the MFi NDA and nobody is going to risk his ass.
Actually you won't get any MPMediaItem because your iPhone isn't playing the songs but your car's accessory connected to the iPhone is accessing the media library. In doing so, it is responsible to update all the metadata of the accessed objects (songs), especially incrementing the playcount and updating the last accessed date of the song. It also stores some information of where in the song it is (position) in the iTunes library.
This information is read by the lock screen to update the cover. This is also what helps the iPod app to continue where your car's accessory left.
So tap into the library and get the latest information from there. Have a look at the TopSongs example project to get started.
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.