Why the music player stop playing music when taking photo? May I know what is the reason why Android phone's music player will stop playing music when I switch to camera mode?

I find it logical if the music player stop playing music when taking a movie but stopping playing music when taking photo seems to be quite illogical since the photo taken will not save any sound.
This is an old question, but I think that some people might find it useful since I came it across using Google search.
The camera app has a permission called TAKE_AUDIO_FOCUS which it is granted by default to it. The camera app uses this to pause the music while you open the viewfinder on your phone.
To fix this issue, you can simply disable the TAKE_AUDIO_FOCUS permission from your phone. The problem here is that you can't do it via the UI since the toggle for it isn't there.
The simplest way to not allow the camera app on your phone to pause your music is to take off this permission using the adb shell.

Download your OEM USB drivers from your phone's manufacturer's website. A simple Google search should give you the link.

Download Minimal ADB portable and extract it to a folder on your desktop.

Connect your phone to your PC and enable USB Debugging. For that, Go to Settings &gt; About Phone &gt; Tap on the Build Number 7 times. This will unlock the Developer options on your phone. Now, Go to the Developer mode from Settings. Enable USB Debugging.

Now, open the folder where you extracted the Minimal ADB and Shift + Right-click on an empty space. From the context menu, select Open Command Window Here.

In the command window type adb devices.

Press OK on your Android phone when it asks you to give the permission for USB Debugging.

Now, type adb shell to open the command line interpreter on Android.

Type the following command to remove the TAKE_AUDIO_FOCUS permission from your Camera app:
appops set app.package.name TAKE_AUDIO_FOCUS ignore


You will need to replace the app.package.name with the app's package name of the camera app in your Android phone. Since most manufacturers don't follow a single standard for naming their camera apps, you'll need to use a package info app from the Play Store to know the package name. Use App inspector for this.
Suppose your phone is a Moto G. You can type the following command to remove the TAKE_AUDIO_FOCUS permission
appops set com.motorola.cameraone TAKE_AUDIO_FOCUS ignore

That should be it.
Source: my own article here.