Are you sure the test video you are trying to play supports 5.1 channel sound? It may be your video is playing stereo only. Verify the video offers 5.1 surround sound and that has been selected.
The cable looks correct, but verify it supports a Toslink 5.1 optical connector and a mini optical connector for the iMac. This has nothing to do with MIDI. Perhaps you are not connecting to the correct ports.
Plug in the cable to your Pioneer system and ensure the Pioneer system is powered on. Plug into the iMac’s output port (the port with the headphones icon). Open System Preferences/Sound and click on Output tab. You should see an entry for your line-out. Select that entry and verify the other sound settings are appropriate.