How-To: Network Shared DB with DLNA Server (Windows)

Get answers about how to share with different devices.

Moderator: Gurus

Posts: 11
Joined: Mon Nov 21, 2011 1:24 am
Location: Ashland, OR

How-To: Network Shared DB with DLNA Server (Windows)

Post by LemurTech »

I am putting this out there for all to reference, since it's something that I really struggled with, and others may be struggling with or simply curious about.

I wanted to have MMW running on a home server (Windows 2012 R2) where I put all my media. I also wanted to use the MMW DLNA server capabilities to stream media to other devices around the house. I needed to be able to manage the media library on the home server, as well as my personal Windows 10 PC.

First, you need to set up for using a shared database, and make sure that all your media is being scanned in using UNC (network) paths. This has been covered in detail elsewere, so I won't repeat any of that, except to say:

+ Make sure the MediaMonkey installation on your server is using a MediaMonkey.ini file that is located in the program folder, i.e. C:\Program Files (x86)\MediaMonkey. This allows all users of the PC to get the same configuration, and simplifies things for our purposes.
+ With a shared DB configuration, you can never have two instances of MediaMonkey trying to access the same database concurrently. (You will get a warning that the DB is not accessible and do you want to create a new one, which you don't!)

So now on to the DLNA bit, which is where things can get really hairy. You can't simply install the DLNA service on your server and leave it running all the time, because when you go to manage your media from your personal PC, it will be trying to connect to the same database that the DLNA service is using (and this will typically fail). You would need to first stop the MediaMonkeyService on your server, either by logging into the server directly, or by issuing a command over the network. Then, when you are done running MMW on your personal PC, you would need to close MMW on the personal PC, and then restart the MediaMonkeyService on your server. This is a pain.

My solution is to create a separate instance of MMW on the server, running as a service, with a separate copy of the database, which is refreshed on a daily basis using a scheduled PowerShell script. The downside of this method is that you won't be able to update play counts to your "live" database. If you can live with that, then this is how you proceed:

1. On your Windows server, open MMW and create and configure a new DLNA server. Install the service.

2. Test DLNA streaming to another device on your network. (But of course, DON'T try to use MediaMonkey on that personal PC that shares the database with your server! Doh! Try Windows Media Player, instead.)

First test with MMW open on your server. Does that work? Is your server firewall allowing incoming connections to the MediaMonkey.exe application? (Those firewall rules should have been created during program installation, but maybe not...?) If this part isn't working, you'll need to troubleshoot. There are plenty of forum posts on this topic, whose sagely advice I shan't repeat.

3. If all seems good at step 2, close down MMW on the server; this will automatically start up the Windows service "MediaMonkeyService". Retest DLNA streaming to your devices.

Now the fun begins.

4. On the server, create a new folder alongside the folder that holds your MediaMonkey database. Put a copy of the MM.DB into this folder. For example:

E:\Config\MediaMonkey <-- original database folder, shared over the network
E:\Config\MMServer <-- folder into which you put your database copy (which does not need to be shared)

5. Create a scheduled task that will run a script to do the following, at minimum: a) Stop the MediaMonkeyService; b) Copy the MM.DB from the original folder into the new location; c) Restart the MediaMonkeyService. You should schedule the script to run once or twice a day, during a time when you can be fairly certain nobody will be trying to use the DLNA streaming.

My own preference is to schedule a PowerShell script that does a little more than the minimum. Feel free to adapt it to your needs:

Code: Select all

$srcFile = "E:\Config\MediaMonkey\DB\MM.DB"
$dstFile = "E:\Config\MMServer"
$logFile = "E:\Config\MMServer\CopyLog.log"

#Stop MediaMonkeyService
$MediaMonkeyService = Get-Process MediaMonkeyService -ErrorAction SilentlyContinue
if ($MediaMonkeyService) {
  # try gracefully first
  Write-Host 'Stopping Service...'
  Stop-Service MediaMonkeyService
  # kill after five seconds
  Sleep 5
  if (!$MediaMonkeyService.HasExited) {
	Write-Host 'Killing Process...'
    $MediaMonkeyService | Stop-Process -Force

#Check for MediaMonkey process (main program is active)
$MediaMonkey = Get-Process MediaMonkey -ErrorAction SilentlyContinue
if (-not $MediaMonkey) {
  # Do copy
  Write-Host 'Copying database...'
  Copy-Item $srcFile $dstFile -force
  $Date = Get-Date -format u
  Set-Content -Path $logFile -value "Last Copy: $Date" -force

#Start service if it was stopped
If ($MediaMonkeyService) {
	Write-Host 'Restarting Service...'
	Start-Service MediaMonkeyService

Remove-Variable MediaMonkeyService
Remove-Variable MediaMonkey
6. On the Server, shut down MMW and make sure the MediaMonkeyService is stopped. Now create a subfolder at C:\Program Files (x86)\MediaMonkey\Service. Copy all the program files from C:\Program Files (x86)\MediaMonkey into that subfolder.

7. Open up C:\Program Files (x86)\MediaMonkey\Service\MediaMonkey.ini in a text editor, and under [System] change the "DBName=" parameter to point to the new copy of your MM.DB (in my example, this would be "DBName=E:\Config\MMServer\MM.DB"). Save and close.

8. Open Regedit and navigate to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\MediaMonkeyService. Edit the ImagePath REG_SZ value to point at the MediaMonkeyService.exe in your new "Service" subfolder. For example: "C:\Program Files (x86)\MediaMonkey\Service\MediaMonkeyService.exe". Clost Regedit.

9. This step will save you much frustration. On the server, you need to create a new firewall rule that allows incoming connections to the MediaMonkey.exe in your new "Service" subfolder, because *this* is the executable that the DLNA service is now going to run. Make sure your firewall is created for the appropriate Profile (Domain, Private, and or Public). For non-domain network, "Private" should be sufficient.

9. Now restart the MediaMonkeyService. The service will start up an invisible instance of MMW that is pointed at the new DB location.

10. Test DLNA streaming from another PC/device. If you've followed these directions carefully, it should work. And if you open MMW on your personal PC, you should have no DB access conflict, and should be able to browse and play from your DLNA server.

Note that, if you open MMW on your server, the MediaMonkeyService will be stopped, and MMW will take over DLNA duties using the "live" database; when you close it down, the MediaMonkeyService will resume DLNA dutes using the copied DB.

I struggled for many hours to get this working, so I hope someone else may profit from my frustration!
Windows 10 Pro 64-bit / MediaMonkey for Windows v4