Bug https://bugs.kde.org/show_bug.cgi?id=400979 describes a problem in the Phonon KCM (System Settings - Hardware - Audio and Video - Device Preference) where the "Test" button, contrary to its description, always plays the test sound through the default sound device. This can also be verified with a command line audio playing tool such as http://github.com/martenjj/phononplay, where even if an explicit output device is specified the sound always plays through the default device.
According to comments at https://forum.videolan.org/viewtopic.php?t=98766, the VLC output device must be set (using libvlc_audio_output_device_set) after setting the media source (using libvlc_media_player_set_media). However, in the current implementation of Phonon it is set (in MediaPlayer::setAudioOutputDevice) before setting the media source (in MediaPlayer::setMedia which is called by MediaObject::play).
Because libvlc_media_player_set_media is called internally by MediaObject::play, it is not possible to do these calls in the correct order from either the KCM or any other Phonon application.
This patch fixes the order of the libvlc calls. It is trying to be as simple as possible and so simply saves the device parameters to MediaPlayer::setAudioOutputDevice as well as setting the device there and then (for compatibility). If those parameters have been saved then it sets them again in MediaPlayer::setMedia after the media source has been set. No changes to the KCM, any calling applications or the Phonon API are required.
With this change, the KCM works correctly and sound can be played through any specified device.