yashsingh1/xdaforums huggingface dataset:
[Nexus One Android Development] rotohammer:
Attached is a current cm-5.0.6 kernel with my tweaks to fix this annoying bug. I'd like some folks to test it to see if it needs further adjustment.

Follow instructions for installing the kernel from this thread:

http://xdaforums.com/showthread.php?t=652594

I haven't been able to trigger the bug at all anymore.
[Nexus One Android Development] RaistlinMaje:
I'll check this out when I get home as I've encountered this on multiple occassions, good work on this
[Nexus One Android Development] jlevy73:
Thank you kind sir will definitely give this a shot.
[Nexus One Android Development] prettyboy85712:
Nice work. I'll give it a try.
[Nexus One Android Development] alapapa:
nice.

just curious..what'd you tweak? got a diff?
[Nexus One Android Development] popopow:
It's possible to fix it without any kernel patch.

Go to music settings and uncheck "unpause on connect".

It looks like sometimes when you unplug a headphone the phone thinks you are plugging it in.
[Nexus One Android Development] shmigao:
unfortunately that doesn't fix the problem.
[Nexus One Android Development] Gr8gorilla:
It has been posted elsewhere, but here it is again.

The bug seems to come from the fact that the phone was designed for use with a 4-pin jack. Compare the jack on the stock headphones to one without inline mic.

Note the difference? The one on the right is the stock jack. The one on the left is a set of SkullCandy headphones.

If you unplug the stock headphones, no random music starting.

Unplug a non-4-pin headphone = Ghost Music.

Don't know if that matters or not but that is where the bug comes from.
[Nexus One Android Development] 1wayjonny:
This seems like a great way to think about it but I would half to turn this being the BUG as negative. Because Bluetooth users that have the music profile paired to their radio experience the same thing and it has no plug.

Many users of stock and compiled roms experience it with plug and/or Bluetooth.

*** EDIT ***

This happens to bluetooth setup with a droid in the office running cyanogen, its very repeatable when walk up to the car.
[Nexus One Android Development] 1wayjonny:
As the other users said it doesn't fix the problem but this option does help contain it. It still sneaks through here and there
[Nexus One Android Development] jchap2k:
Great! I wanted a fix for this for so long!! :D

Does this also fix the random song skipping that you can experience if you move the non 4-pin 3.5mm plug around while playing music?
[Nexus One Android Development] rotohammer:
I haven't looked at the bluetooth variation of this bug. Now that I am aware of it, I'll look to see if the two situations are due to a common cause. Initially I was just thinking it was the physical phone jack insert/removal that was the root cause.

I'd still like feedback from folks with wired headsets that can test this kernel for any improvement.

So far I haven't heard from anyone.
[Nexus One Android Development] Gr8gorilla:
Ok take your stock headphones and plug in and unplug them 10 or 20 times and see how many times the music starts on its own.

Then take some non-stock 3-pin head phones and do the same thing. Post your results.

It may not be the only thing going on, however, it does help nail down the problem because as of this writing I have never had this issue with a four-pin jack but I have it every time I unplug a 3-pin jack.
[Nexus One Android Development] FormelLMS:
As I said:

The Problem comes with the Musik2.1-update1.

In one of the ROM updates was an update of the Stock Music Player I think.

With the first ROMs there are no problems with Music.
[Nexus One Android Development] jchap2k:
Nope. I had this issue since day 1, with original stock rom.
[Nexus One Android Development] FormelLMS:
Yes, really? Strange, I have this problem since one of the latest updates.

Has someone reported this problem to HTC?

In Germany, the Nexus One isn't officially buyable. My device is imported and I can't report this bug to HTC Germany.
[Nexus One Android Development] 1wayjonny:
This has happened to the G1 at points and the Nexus with stock or compiled rom
[Nexus One Android Development] 1wayjonny:
Great this is killer bug that needs to go away, WE will all donate if you knock this out and get you another BIG cigar!

Here is link with even other people mentioning the bluetooth issue as well. http://forum.cyanogenmod.com/index.php?/topic/877-randome-music-starts-playing/page__hl__audio

The headset 4 pin vs 3 pin def has an effect and causes issues but its not the only thing going on with all the reported problems.

It goes across multiple phones not just the Nexus

What did you configure / change in the your upload?

Thanks
[Nexus One Android Development] diversificationied:
Nope, you're wrong, I've used regular headset since day one, and I've never come across this issue.

It's more than likely an issue with faulty jacks making the rounds.
[Nexus One Android Development] Gr8gorilla:
What regular headphones are you using? Can you confirm 4 or 3 pin jack?
[Nexus One Android Development] anod:
Headphone connector causes music player to automatically start in party mode. Some users have reported that using different headphones or "2.5mm to 3.55mm" converters have helped, but do not resolve the issue completely. This bug has been resolved by the installation of the "Autostarts" app and by going into the "music button pressed" section, clicking on "music" and then pressing "disable"

http://wiki.modaco.com/index.php/Huawei_U8220#Known_Issues

It works for me. I think "audio jack" and Bluetooth call the same event: "music button pressed"
[Nexus One Android Development] :
3 pin jack, some cheap $20 skull candies. I already tried a bunch of random headphones(all three pin) I had laying around about a month ago when I read a similar thread.

My phone was gang raped by a myriad of faceless monsters for about thirty minutes. lol Still not an unwanted peep from the phone.
[Nexus One Android Development] cyanogen:
You can't just post a binary kernel and say it fixes a bug :) What has changed?

As far as I've found so far, the bug is caused by the very delicate "auto" mutexes used in the media layer. The kernel changes introduced in 2.6.30 made it worse, but I found that enabling NORMALIZED_SLEEPER in kernel/sched_features.h minimized the issue. Unfortunately, it still happens. If you rebuild with NORMALIZED_SLEEPER disabled (the default), you'll get random music ALL the time and certain media types will even deadlock the system (FLAC in particular). NORMALIZED_SLEEPER is being removed in 2.6.34, so this causes me some concern.

I've been all over this with GDB, ppppplease share :)

If you are good with GDB, and nasty concurrency issues, make the change I suggested above in the kernel, attach gdb to mediaserver and try to play a FLAC file. You'll see it blocked trying to acquire the automutex in getCurrentPosition(). I'm 99% sure these problems are related.
[Nexus One Android Development] FormelLMS:
Yes, it can't be the connector of the headphone.

Since today I have the DekstopDock.

It connects via Bluetooth to play audio. If you don't hear some songs and take the phone out of the dock or disable the bluetooth, the music starts, too.

I hope, that somebody fixes the problems. It's really bad.
[Nexus One Android Development] rotohammer:
Sure I can :) But seriously, I only said it fixes it for me, If no one wants to test it to see if it works for them, well thats just sad.

Now that I know theres more to the problem (ie: a2dp as well as wired headphones), it could be a more subtle and insidious issue as you stated. I didn't get into debugging, I started from where I thought the root cause would be, and thats in the hardware driver.

Last night I posted the changes to irc, kmobs gave it a go, but it did not fix the bluetooth issue, and I didn't expect it to. There could be two similar but unrelated bugs here, or just one deep one.

We all can discuss further on #cyanogen as i don't have the patience to work through the hardware/software interactions over a forum :)

Hint, I increased the timeouts for i/o line debouncing.
[Nexus One Android Development] alapapa:
speaking of software interactions...the problem seems to be exacerbated on my devices when MortPlayer, Pandora, etc. have been launched at any point after a reboot (regardless of the setting in the music app). yay anecdotes.
[Nexus One Android Development] djmcnz:
"Media button pressed" but otherwise works great for me... and I can't find a media button on my Nexus so I'm sure I'm no losing anything... bet I forget to change that every time I drop a new rom though...

Thanks!
[Nexus One Android Development] SiNJiN76:
:eek: Waaaay Over My Head!!! :D
[Nexus One Android Development] HumpDdumpD:
I've had similar problems with my g1 & now my nexus as well. Same thing fixed (well contained) it on both phones. Go into your now playing list, menu, clear now playing. You loose where you were on a song, but no more phantom music :-)

I haven't seen this posted anywhere as of yet, has worked for me 100% of the time. I'm curious if it will work for everyone though.
[Nexus One Android Development] cyanogen:
That makes sense and if it does help, we have multiple problems on our hands.
[Nexus One Android Development] Gr8gorilla:
I also compiled this into my Team n0ob, Fireball-kernel. I will ask the guys using that to comment over hear if they notice any change.
[Nexus One Android Development] karthikjr:
yes! I posted this on the cyan thread a while ago, but it was buried under an avalanche of posts discussing something else. This fix works. And works perfectly all the time. I use my phone as a music player on my daily commute, And this is the only fix that works for me every time.
[Nexus One Android Development] 1wayjonny:
Even though I mentioned Bluetooth heavily needed the fix as well. I must say for the past two days i have sat in my car with Pandora playing.

This is connected RCA to the stereo using a huge fat adapter that always caused the problem. I played a song on Pandora and unplugged and replugged the headset in over and over and over, like had to be over 50+ the spun the phone to cause static around at least 20x times.

I must say that so far nothing has happened. I will have to do more testing as Cyanogen fixes also has contained the issue a bit but it still happens.

So far I have been trying to to reproduce it and it has not happened. The delayed timing on the I/O seems to have worked but I need more testing time.

Thanks Roto for the effort so far

** EDIT **

I drive 2 hours every day so I have plenty of time to test, the issue always seemed worse withs colds car mornings cause the wires were stiffer with slight condensation and caused the issues more ( I have thicker wires). I had one of these this morning and no problem as well.

Knock on my virtual wood.
[Nexus One Android Development] Devastatin:
I just looked on every screen within the media player. I don't use playlists and can't find the screen you mentioned.

And I do have the bluetooth bug. Easy way to replicate it.

Have bluetooth on, playing music.

Answer a phone call

Music will pause automatically

End call,

Music will unpause automatically and will continue playing

Pause music manually.

Walk out of range of the bluetooth device.

Music restarts automatically.
[Nexus One Android Development] Gr8gorilla:
As far the headphone issue goes, I have not been able to create the random music event since compiling this into my Kernel. I have not heard anything from others using it. But so far this seems to be a good work-around, even if it doesn't fix the root cause of the bug.
[Nexus One Android Development] rotohammer:
I have a gut feeling where the bluetooth bug is (libaudio), and its an area of interest for me because I'm trying to get non-a2dp BT-SCO headsets working for media playback, and looking at the spaghetti of logic thats in libaudio I'm surprised it works as well as it does :)
[Nexus One Android Development] jlevy73:
No headphone issue for me as well after using Roto's fix/work around :)
[Nexus One Android Development] jz9833:
Did cyanogen include this in 5.0.6? I looked in the changelogs and didn't notice anything
[Nexus One Android Development] rotohammer:
It needs more than a half day of testing. Now if everyone would have got off their ass 2 days ago, maybe it would have made it into 5.0.6 :)

If nothing changed in the kernel since Wednesday, then the kernel I posted should be identical except for the fix.
[Nexus One Android Development] tropmonky:
Yeah, I use my phone in the car with the google dock and without the google dock... it's an issue with Bluetooth or wired.. doesn't seem to matter.

It just seems like there is something in the system telling it to start music when something is detached. It can be Bluetooth or the audio jack being unplugged and it does the same thing.
[Nexus One Android Development] rotohammer:
The bug seems more consistent using bluetooth, where as the wired headset triggered the bug randomly.

Anyone agree or disagree with this observation?
[Nexus One Android Development] Devastatin:
Take a look at the logic around resume on connect.

If its unchecked maybe it does the reverse and resumes on disconnect.
[Nexus One Android Development] jz9833:
Thanks rotohammer. I've been using an UV/OC kernal, but this fix is alot more important to me. I'm going to try it out wtih 5.0.6 tonight.
[Nexus One Android Development] rotohammer:
Rotohammers Excellent Kernel of Awesomeness

Keep in mind, I post the kernels for testing purposes only. You'll never see "Rotohammers Excellent Kernel of Awesomeness" posted here. The game plan is this: I'll work on fixing bugs and will post test kernels/apps for folks to evaluate as long as there is participation. As soon as a test shows to have value (partial or complete bugfix), I'll immediately release the source here and on #cyanogen for peer review and collaboration. I don't have a lot of time to spare, but I'll do what I can.

PS: Only I run "Rotohammers Excellent Kernel of Awesomeness" heh
[Nexus One Android Development] jlevy73:
Thanks Roto much appreciated.
[Nexus One Android Development] FormelLMS:
Full agree. With bluwetooth the problem is every time, with audio jack it is sometimes (most times... but not every time)
[Nexus One Android Development] cdmove:
is there a way to disable this autoplay "bug"? everytime i turn off my car which turns off the bluetooth, the music starts to play.

i'm running CM5.0.6 N1.
[Nexus One Android Development] rotohammer:
I'm working on it.
[Nexus One Android Development] cdmove:
sweeet!

thanks, dude.
[Nexus One Android Development] 1wayjonny:
More days of brutal wired testing ...

So far so good still!

Ill keep posting
[Nexus One Android Development] karthikjr:
You don't need to use playlists. The music player creates one for

you on the fly, every time you play any music (even a single song).

On your "Now Playing" screen, the one that shows the album

art of the song's that's currently on, click on the top right button.

That shows the current playing queue. Hit "menu" and "Clear Playlist/Queue".

And try getting the bug to rear its ugly head.
[Nexus One Android Development] rotohammer:
Thanks for the feedback. Also, pay attention for something that doesn't work correctly, in case I caused some collateral damage. Its not uncommon to fix one thing and break another :)
[Nexus One Android Development] FormelLMS:
What can I do to help you? (By using MCR Rom)
[Nexus One Android Development] uberingram:
I use the official Car Dock and stream to my stereo via BT twice a day so I was getting this issue hard core. I used Titanium backup to remove the stock music player completely (which is hardly a good solution but I use Google Listen and tunewiki exclusively) and I have yet to experience the ghost music bug again. Please note that this causes the Clock app to crash if you hit the Music button (duh).

This is entirely anecdotal.
[Nexus One Android Development] rotohammer:
Well, I found a bug. Actually my wife found it. Now you can't use the HTC headset to make a phone call.

Ill fix that in the morning. That is why we test :)
[Nexus One Android Development] Gr8gorilla:
Just made a call using the headset. I compiled my kernel with your fix. I have not had any issues with the unplug/random music start bug, and I am not noticing any issues with making calls except that they are loud as hell.
[Nexus One Android Development] tropmonky:
just clearing the playlist has worked for the past couple days for me.. just an update.
[Nexus One Android Development] :
Had my first encounter with this today in class, through bluetooth.

Turned on bluetooth on my phone, then my S9 headset.

-Used the music player for about 10 minutes, then used pandora for another ten minutes*

(should note that I started pandora before putting the regular music player on pause)

-Got to class, his pause through the S9 headset.

-Turned off the headset

-Music started playing on the phone(from the music player and not from pandora)

I normally turn off bluetooth on my phone before I turn off the headset and never have an issue of autoplay.

Hope that gives some further clues as to what's going on with the auto play.
[Nexus One Android Development] travon802:
Clearing the Now Playing list in the Music app solved the problem for me. I only use wired headphones though. I really need to find out how to delete the Music app, without causing FC's in Gesture Search (i.e. assigning another default media player)
[Nexus One Android Development] 1wayjonny:
Ok i had removed the fix to see if i can get 5.0.6 to replicate it and I got it to do it twice. Played Pandora, turned screen on from sleep when leaving the car, removed audio jack and it happened two days in a row.

So now I am going BACK to your fix, which I have not been able to replicate .... YET!=)
[Nexus One Android Development] :
Some more info that I think might help.

With my bluetooth headset,I have play/stop/pause functions. If the do the following the stock media player plays by itself:

-pause music via headset

-turn off bluetooth headset (without turning off bluetooth on phone)

This will have the phone playing the music. The state of the button on the media player will not change however. It'll play music, but I have to press the play button twice to actually pause it.

However, If I stop the music via the "stop" function on the headset, then turn the headset off, the stock media player will not start playing music by itself.
[Nexus One Android Development] 1wayjonny:
Significant others always seem to find these bugs don't they. I have a Windows 7 media center girl at home who has a list of thing for Microsoft.
[Nexus One Android Development] crazyknallchopf:
sry my bad english

i have original nexus one dock, everytime i get the n1 away from dock it starts the ghostmusic!

after flashing zimage, no more working wifi :-(

restored back to pre-audiopatch
[Nexus One Android Development] klaberte:
I posted a fix for this a while back

http://xdaforums.com/showpost.php?p=5876305&postcount=37

Does this help in this context?
[Nexus One Android Development] cdmove:
how did you configure Autostarts to disable Music?
[Nexus One Android Development] attn1:
Wrong. Mine does it with the stock headphones.
[Nexus One Android Development] frandavid100:
Same here!
[Nexus One Android Development] crazyknallchopf:
aaah... you mean Autostarts and not Autostart (root)

i will trying it... thx
[Nexus One Android Development] crazyknallchopf:
Works perfectly for me :-)

thx
[Nexus One Android Development] 1wayjonny:
No your fix was mentioned here already but this thread is for taking care of the problem at the source level, that is why roto has posted modifications for the kernel.

But yes that works using autostart to disable but that is a temp solution...
[Nexus One Android Development] djmcnz:
Well... it's permanent, just not root cause.
[Nexus One Android Development] vk2bea:
Where is the "Music Settings" ?
[Nexus One Android Development] rotohammer:
I'm glad to see some more insight to how the problem exists and the various work arounds. I'm also not convinced that my tweaks are the best solution.
[Nexus One Android Development] gizmo2431:
Just some FYI info for any developers...

I have used stock headphones since day 1 of having the phone. On the stock rom I NEVER had this issue. I flashed CM 5.0.6 this past weekend (my first ROM flashed on the device) and I now have song skipping occasionally and ghost music when I unplug my headphones.
[Nexus One Android Development] cdmove:
i think someone suggested clearing the playlist in the Music app and that did the trick.

no more unwanted music playing whenever i disconnect from bluetooth.
[Nexus One Android Development] rjhay22:
Hey bro, I just saw this message, but I am using skull candy, and dont have the music bug, is this bug random?
[Nexus One Android Development] karthikjr:
I'm one of the "someones" who posted this workaround. :)

And it works not just for the music app, it works on Mixzing music player too.

The other thing that you oughta note is that there is some link

between putting a music widget on your homescreen and the ghost

music. Someone else had suggested that removing the music widget

off your homescreen would eliminate this problem. I've tried this,

and yes it does work. A combination of clearing the NowPlaying list

and NOT running any music widgets (stock player or mixZing) should

take care of everything.

But props to you, roto, for getting a discussion going around this

irritating issue.
[Nexus One Android Development] 1wayjonny:
I get the bug a lot and I have never used a Music or Pandora widget...
[Nexus One Android Development] bmj1086:
So the fix for an issue is to not use one of the best widget options [music] and to keep songs out of your playlist? That seems a bit extreme if you ask me. Honestly I hate the fact that the music plays when I disconnect Bluetooth but I'd rather have that then not have my music and last.fm widgets.
[Nexus One Android Development] bmj1086:
It's funny how people also blame the type of headset or anything about the headset because it has nothing to do with a physical headset. Mine does it when I disconnect my Bluetooth headset, When I take the phone off the dock [which disconnects bluetooth], when I power off the Bluetooth headset when it's not playing music, etc. I don't use a physical headset at all.
[Nexus One Android Development] Treatcon:
I get this bluetooth bug as well, many, many times and it was quite annoying. My bluetooth on the N1 auto connects to my trucks bluetooth stereo which I only use for phone calls, hands free. I turn off my truck and walk away... I never manually press any buttons or whatever on my stereo or N1 (auto connecting like it should). Now sometimes I get the music playing and sometimes I don't. If I had to guess it would happen maybe 30% of the time. I have also never used any headphones on my N1 and all my music is played through my iTouch. So when music starts to play I get the default stuff that comes with the phone, or some custom ring tones.

For me, I think I traced the problem down. It did stop happening when I removed the checkbox from "Media - Use for media audio" in the options for the connection to my bluetooth stereo. No more problems at all with the music bug. It's been 2 weeks now and it hasn't happened once. I'm in and out of my truck all day and bluetooth is constantly working its butt off.

So if you want to try this "fix" long press on the bluetooth connection for your device and choose Options and uncheck the box for "Media - Use for media audio" if you are only using bluetooth in your vehicle for hands free calls.

:)