Bug 836201 - [FM Radio] Music is not playing while FM is playing in background. r=jlebar, a=leo+
authorMarco Chen <mchen@mozilla.com>
Mon, 15 Apr 2013 23:02:12 +0800
changeset 119068 5eb76dd7c2a48483c9819d0079ad2ee313f89aab
parent 119067 0f04a689798e953197576eaf03c7e989eebf9280
child 119069 46c4a4871118d0dd04a4a1c52fb7f90e9a154724
push id669
push userryanvm@gmail.com
push dateMon, 15 Apr 2013 20:37:17 +0000
reviewersjlebar, leo
bugs836201
milestone18.0
Bug 836201 - [FM Radio] Music is not playing while FM is playing in background. r=jlebar, a=leo+
dom/fm/FMRadio.cpp
dom/fm/FMRadio.h
--- a/dom/fm/FMRadio.cpp
+++ b/dom/fm/FMRadio.cpp
@@ -260,20 +260,29 @@ void FMRadio::Notify(const FMRadioOperat
 }
 
 /* void canPlayChanged (in boolean canPlay); */
 NS_IMETHODIMP FMRadio::CanPlayChanged(bool canPlay)
 {
   nsCOMPtr<nsIAudioManager> audioManager =
     do_GetService(NS_AUDIOMANAGER_CONTRACTID);
   NS_ENSURE_TRUE(audioManager, NS_OK);
+
+  bool AudioEnabled;
+  audioManager->GetFmRadioAudioEnabled(&AudioEnabled);
+  if (AudioEnabled == canPlay) {
+    return NS_OK;
+  }
+
   /* mute fm first, it should be better to stop&resume fm */
   if (canPlay) {
+    audioManager->SetFmRadioAudioEnabled(true);
     int32_t volIdx = 0;
     // Restore fm volume, that value is sync as music type
     audioManager->GetStreamVolumeIndex(nsIAudioManager::STREAM_TYPE_MUSIC, &volIdx);
     audioManager->SetStreamVolumeIndex(nsIAudioManager::STREAM_TYPE_FM, volIdx);
   } else {
     audioManager->SetStreamVolumeIndex(nsIAudioManager::STREAM_TYPE_FM, 0);
+    audioManager->SetFmRadioAudioEnabled(false);
   }
   return NS_OK;
 }
 
--- a/dom/fm/FMRadio.h
+++ b/dom/fm/FMRadio.h
@@ -40,19 +40,19 @@ public:
                                                    nsDOMEventTargetHelper)
   FMRadio();
   virtual void Notify(const hal::FMRadioOperationInformation& info);
   virtual void Notify(const hal::SwitchEvent& aEvent);
 
 private:
   ~FMRadio();
 
+  nsCOMPtr<nsIAudioChannelAgent> mAudioChannelAgent;
   hal::SwitchState mHeadphoneState;
   bool mHasInternalAntenna;
   bool mHidden;
-  nsCOMPtr<nsIAudioChannelAgent> mAudioChannelAgent;
 };
 
 } // namespace fm
 } // namespace dom
 } // namespace mozilla
 #endif