[MTCD Android Head Units General] jtrosky:
This thread is for discussing idea and methods that can be used to allow media playback to resume playback where it left off after unit comes back out of sleep - especially when music is stored on SD card or using online music services.

While setting up my Eonon MTCE unit "on the bench", I quickly found that something as simple as resuming music playback from where it left off before entering sleep mode wasn't "automatic" - especially when your music is stored on an SD card (which Android automatically checks for errors every time the unit comes out of sleep mode) - or if using online media.

Here is how I accomplished this by using Tasker (and the AutoNotification plugin).

My problem was this... I am using the app Car Launcher Pro - and plan to stay at the Car Launcher Pro screen most of the time (provides nice big clock, date, weather, album art, etc). Car Laucher Pro allows you to change media players and skip songs right from it's screen, so most of the time, I have no need to ever leave my "launcher" screen - regardless of what app I'm using for media playback. I wanted to be able to have the unit continue the song that it was last playing when it went into sleep mode - whether that be through my local media player app (PowerAmp in my case) or an online service (Pandora or Spotify in my case). This turned out to be a lot harder that I expected. :) With most apps, if you attempt to resume playback too soon (before the SD card is mounted or before you are back online), playback will fail, which is why I set things up to wait for the SD card to be mounted (or wifi to become available for online music services) before attempting to resume playback. Using this method allows me to resume right where I left off when the unit was shutdown - all automatically (I also use Tasker to automatically put my phone into hotspot mode when it sees the radio bluetooth). So far, it works perfectly. Although, there are probably dozens of ways to do this - all slightly different depending on your exact setup. This is just the way *I* did things for my setup...

So here is the screen that I normally see - my "launcher" (Car Launcher Pro):

View attachment 4636936

By pressing the button in the lower-left-hand corner, I can select what media player i want to use - and can skip songs using the on-screen music controls or my steering-wheel controls. Like I said, regardless of what I had playing when I shut the car off, I wanted it to just pick up where it left off when I restarted the car (without the song starting over). In order to do this, I found that I had to pause the player before the unit went to sleep and then resume playback when the unit came out of sleep. If playing music from SD card, I had to make sure the SD card was available before resuming playing and if listening to an online music service, I had to wait until wifi was reconnected before resuming playback. I was able to do all of this using Tasker and the AutoNotification plugin (auto-notification plugin was needed to determine what media player was active so I knew wheher I had to wait for the SD card to be available or the wifi to be reconnected before resuming playback).

Here is my entire Tasker setup for this (note also that when I run one media playback app, I also kill the other media players so that only one is running at a time) - all media players and Car Launcher Pro are in my whitelist:

[b]Profile: PlaySDAfterSleep (3)[/b]
Event: Card Mounted [ Card Title:Music Frequency:* ]
State: Variable Value [ %CPPLAYER ~ PowerAmp ]
Enter: PlayMedia (21)

[b]Profile: GoIntoSleep (5)[/b]
Event: Intent Received [ Action:com.microntek.bootcheck Cat:None Cat:None Scheme:* Mime Type:* ]
Enter: PauseMedia (2)

[b]Profile: PandoraRunning (14)[/b]
State: AutoNotification Intercept [ Configuration:Persistency Type: Persistent Only
Notification Apps: Pandora ]
Enter: KillPA_and_Spotify (9)

[b]Profile: PowerAmpRunning (17)[/b]
State: AutoNotification Intercept [ Configuration:Persistency Type: Persistent Only
Notification Apps: Poweramp ]
Enter: KillPandora_and_Spotify (11)

[b]Profile: SpotifyRunning (18)[/b]
State: AutoNotification Intercept [ Configuration:Persistency Type: Persistent Only
Notification Apps: Spotify ]
Enter: KillPA_and_Pandora (13)

[b]Profile: PlayOnlineAfterSleep (20)[/b]
State: Wifi Connected [ SSID:* MAC:* IP:* Active:Yes ]
State: Variable Value [ %CPPLAYER !~ PowerAmp ]
Enter: PlayMedia (21)

[b]Task: PauseMedia (2)[/b]
A1: Run Shell [ Command:input keyevent KEYCODE_MEDIA_PAUSE Timeout (Seconds):0 Use Root:eek:n Store Output In: Store Errors In: Store Result In: ] If [ %class ~ poweroff ]

[b]Task: PlaySDMedia (6)[/b]
A1: Run Shell [ Command:input keyevent KEYCODE_MEDIA_PLAY Timeout (Seconds):0 Use Root:eek:n Store Output In: Store Errors In: Store Result In: ] If [ %CPPLAYER ~ PowerAmp ]

[b]Task: KillPA_and_Spotify (9)[/b]
A1: Variable Set [ Name:%CPPLAYER To:Pandora Recurse Variables:eek:ff Do Maths:eek:ff Append:eek:ff ]
A2: Kill App [ App:Poweramp Use Root:eek:n ]
A3: Kill App [ App:Spotify Use Root:eek:n ]

[b]Task: KillPandora_and_Spotify (11)[/b]
A1: Variable Set [ Name:%CPPLAYER To:PowerAmp Recurse Variables:eek:ff Do Maths:eek:ff Append:eek:ff ]
A2: Kill App [ App:Pandora Use Root:eek:n Continue Task After Error:eek:n ]
A3: Kill App [ App:Spotify Use Root:eek:n ]

[b]Task: KillPA_and_Pandora (13)[/b]
A1: Variable Set [ Name:%CPPLAYER To:Spotify Recurse Variables:eek:ff Do Maths:eek:ff Append:eek:ff ]
A2: Kill App [ App:Poweramp Use Root:eek:n ]
A3: Kill App [ App:Pandora Use Root:eek:n ]

[b]Task: PlayOnlineMedia (19)[/b]
A1: Run Shell [ Command:input keyevent KEYCODE_MEDIA_PLAY Timeout (Seconds):0 Use Root:eek:n Store Output In: Store Errors In: Store Result In: ] If [ %CPPLAYER !~ PowerAmp ]

[b]Task: PlayMedia (21)[/b]
A1: Run Shell [ Command:input keyevent KEYCODE_MEDIA_PLAY Timeout (Seconds):0 Use Root:eek:n Store Output In: Store Errors In: Store Result In: ]

I hope this helps someone. Please don't hesitate to ask questions!