Marking an MPMediaItem (podcast) as listened to - iphone

Is there a way to update the 'listened to' status of an MPMediaItem from the iPod library?
I've tried using MPMusicPlayerController in iPodMusicPlayer mode and it does not mark the podcast as listened to once it finishes playing.

As far as I can see it's not possible to change media attributes from MPMusicPlayer controller.
The only thing you could try play back the podcast and jump to the last second, then play back the last second (and turn the volume to 0 for that second).
But this is no good way as well because, you have play back something this causes a stop of every other iPod playback.

Related

AirPlay flickering when switching between movies

I have an app that shows list of movies in a table view. When I play them one after another on device it works just great. But when I switch to Apple TV over AirPlay it doesn't work anymore. It play's the first video on ATV ok but after a switch to the next video the screen on ATV start blinking/flickering and after a few seconds it falls back playing on a device. I am using MPMoviePlayerController for playing stream videos.
I also found out that if previous video finished playing over AirPlay it tries to start the next one over AirPlay also. Is this intended behaviour?
Is this kind a related with property allowsAirPlay?
I think I've found a solution. Before you switch playing another video you should stop the previous one:
[self.moviePlayer stop];
This is not needed if you are not playing via AirPlay cos the next video will automatically stop previous one by nature - you can not play two videos at once.
But If you do play video over AirPlay you need to stop previous one first and than play the next one.
This solution works for me.

How do I make MPMusicPlayerController register changes in playlist?

I'm trying to build a music player app in xcode, but I'm having trouble when changing the playlist (a.k.a. the music player queue). Any time I change something in my playlist (i.e. when addind songs or changing song order, or when pressing the "next" button, etc.) I always seem to have to execute these tow lines of code:
[self.musicplayer play];
[self.musicplayer pause];
apparently, the music player only really registers changes when i send it the "play" command; soon after, i have to send it "pause", so that the song won't actually start playing.
without these lines of code, i would have the following problem (among others):
I would have, say, 6 songs, named "1" through "6". song 1 was playing, but i paused it. I then pressed the "next button" 3 times, which executed the following code (3 times):
[self.musicPlayer skipToNextItem];
therefore, by my logic, the music player should have song number 4 as its current playing song; but when I pressed play, song number 1 would start playing, as if it hadn't noticed I pressed "next".
I was only able to solve the problem by telling it to play and pause, as described above, but that was a very ugly solution, to say the least. also, in some cases, the ipod would play the first seconds of the song before processing it had to pause right away, and that was pretty bad :p
Does anyone know the correct way I should be doing this?
I am using Xcode 4.2.5 preview, and testing it on an iphone 4s with ios 6.

Prevent MPMusicPlayerController from playing next song in que

I am creating an app that has a playlist and uses the MediaPlayer library. When a song ends I don't want the next song to start. I tried to use the MPMusicPlayerControllerNowPlayingItemDidChangeNotification to pause the music player when the song changes, but the song starts to play before I get the chance to stop it. I also tried to use KVO to track the changes to musicPlayer.currentPlaybackTime, but I only receive messages when i manually change the playback time. I can't find any information about this problem anywhere.
In my app I have shuffle and repeat off, and create a queue with only one song in it, then send that to the music player. When the song finishes, there aren't any other songs in the queue, so it stops playing.
That being said, the latest iOS update has stopped reporting the correct playback state when the song finishes and is reporting it as paused when it used to be stopped. Not sure if that's a side-effect of the above method or not.
Are you calling:
player.beginGeneratingPlaybackNotifications()
before adding the observers?

Big problems when adding the same MPMediaItem into an iPod queue - how can I track which one is playing?

I've had a few complaints about my app, InstanTunes, when people are adding the same song twice to the queue, which is queued in the iPod app.
[[MPMusicPlayerController iPodMusicPlayer] setQueueWithItemCollection:collection];
Basically, the problem is that when the user leaves my app and continues to listen to their queue via the iPod app, InstanTunes loses all control and understanding of what is going on. On return to InstanTunes, I'm faced with the problem of the now playing song, given by [musicPlayer nowPlayingItem]; is in my NSMutableArray of MPMediaItems twice but I have no idea what instance of it is the now playing song.
Here's a simple diagram to illustrate:
Is song A at index 0 playing? Or song A at index 2 playing?
Can anyone think of a way for me to be able to tell which instance of 'Song A' is playing when the user returns to my app? As far as I know, I can't tag the MPMediaItems to be played in the iPod app.
This is really annoying, since I don't want to remove the ability to add the same song twice, but it is causing countless problems.
Any help, insight or suggestions would be greatly appreciated.
You can get the index of the nowPlayingItem

Find if an audio is currently playing

I need to find out if my program is currently playing any audio and in case it does, I want to stop the previous audio and start a new playback.
The property kAudioSessionProperty_OtherAudioIsPlaying always returns a 0 (probably only checks whether iPod music is playing)
There's another property kAudioQueueProperty_IsRunning but this always returns a 0 whether the audio is running or not. Can someone please tell me how I can find out if an audio is playing in my app or not.
Thanks.
Note: The class from which I invoke my streamer gets deallocated when I move back in the view hierarchy. So I do not have any way of accessing the AudioFileStreamID to know whether audio is playing. I need to use one of the properties provided by the SDK.
Found a workaround. Instead of creating the streamer object in a viewcontroller, I am using a reference in the appDelegate. This way I'll always have a live reference of the streamer class which I can access in any of the viewcontrollers to know whether audio is currently playing or not.