Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Windows] Media (audio or video) playback stop working after RDP session disconnection #365

Open
itlancer opened this issue Jun 29, 2020 · 1 comment

Comments

@itlancer
Copy link

Problem Description

Media (audio or video) playback stop working after RDP (Remote Desktop Protocol) session disconnection. Problem occurs on remote desktop side of Windows device.
When client RDP session disconnect from remote desktop then AIR application (which works on remote dekstop) doesn't playback Sound anymore (Sound::position property stop updating) and video rendering stop (one frame freeze) or "empty" frame showed (stage color) instead of video (but NetStatusEvent.NET_STATUS continue dispatch NetStream.Play.Start, NetStream.Buffer.Full and other events as "all ok"). New audio/video playback attemps (Sound, Video or NetStream recreation) also doesn't work.
Configuring remote audio settings on RDP connection ("Remote audio playback": "Play on this computer", "Do not play" or "Play on remote computer") mostly doesn't help - audio/video playback will "break" anyway after 2-4 connection/disconnection attempts.
image
Only AIR application restart could "solve" such problems.

It has been tested with AIR 32.0.0.89 and latest AIR 33.1.1.98 with many different Windows 10 32/64-bit devices with different versions and editions. Tested with different videos (MP4 H.264) and audios (MP3 or even programmatically generated via SampleDataEvent).
Same problem in all cases.
Changing renderMode in application manifest doesn't help.
SoundMixer::computeSpectrum() calls doesn't throw any exceptions (like in some other related cases with audio drivers problems etc).
Seting audio device index again (or change it to something else) (via AudioDeviceManager::selectedDeviceIndex) (after RDP session disconnect) doesn't help.
Note: video that contains audio doesn't playback right now with AIR 33 so for AIR 33 to reproduce all such issues you should use video without audio in it (or use AIR 32).
Other applications (non-AIR) works correctly in the same cases (use Chrome browser for example with audio/video playback).

Related issues (not the same):
#80
#155
#151
#93
#87
#224
#250

Steps to Reproduce (case 1)

Note: you need 2 Windows devices in one local network. One - client (that will connect via RDP to second one). Second - "remote desktop" (where we will use AIR application).

  1. Launch code below on "remote desktop" Windows device. It will start to play (dynamically generate via SampleDataEvent) "beep" sound for 2 seconds every 4 seconds. In traces you will see
    no bug
    It indicate that Sound::position property changing and audio playback correctly.
  2. If you were not connected at step 1 via RDP to remote desktop when start AIR application then connect via RDP from client computer to remote desktop (where AIR application started).
  3. Close RDP session (disconnect from it).
    *sometimes you should repeat steps 2 and 3 few times to reproduce issue.

Application example with sources attached.
rdp_audio_bug.zip

package {
	import flash.events.IOErrorEvent;
	import flash.events.SampleDataEvent;
	import flash.media.Sound;
	import flash.media.SoundChannel;
	import flash.media.SoundTransform;
	import flash.utils.setInterval;
	import flash.utils.setTimeout;
	import flash.display.Sprite;
	
	public class RDPAudioBug extends Sprite {
		
		private var _sound:Sound;
		private var _soundChannel:SoundChannel;
		
		public function RDPAudioBug() {
			//Play "beep" sound for 2 seconds every 4 seconds
			setInterval(function():void {
				_sound = new Sound();
				_sound.addEventListener(SampleDataEvent.SAMPLE_DATA, sound_sampleData);
				_soundChannel = _sound.play();
				
				const oldCurrentTime:Number = _soundChannel.position;
				setTimeout(function():void {
					if (_soundChannel.position == oldCurrentTime) {
						trace("bug");
					} else {
						trace("no bug");
					}
					clear();
				}, 2000);
			}, 4000);
		}
		
		private function sound_sampleData(event:SampleDataEvent):void {
			for (var i:int = 0; i < 8192; i++) {
				var n:Number = Math.sin((i + event.position) / Math.PI / 4);
				event.data.writeFloat(n);
				event.data.writeFloat(n);
			}
		}
		
		private function clear():void {
			if (_soundChannel != null) {
				_soundChannel.stop();
				_soundChannel = null;
			}
			if (_sound != null) {
				_sound.removeEventListener(SampleDataEvent.SAMPLE_DATA, sound_sampleData);
				if (_sound.bytesLoaded < _sound.bytesTotal) {
					try {
						_sound.close();
					} catch (er:Error) {
						trace(er.getStackTrace());
					}
				}
				_sound = null;
			}
		}
	}
}

Actual Result:
You will not hear sound anymore (no sound from AIR application at both computers) (even after you close RDP session). Sound::position property doesn't change.
In traces you will see
bug

Expected Result:
Depends on RDP connection audio settings ("Remote audio playback").
After RDP connection with "Play on this computer" you should hear sound on client computer (where RDP connection initiated).
After RDP connection with "Do not play" you shouldn't hear sound anywhere - it's ok because no audio devices left on remote desktop computer.
After RDP connection with "Play on remote computer" you should continue to hear sound on remote desktop (computer).

After RDP session disconnect you should hear sound again on remote desktop (computer) as before.

Steps to Reproduce (case 2)

Note: you need 2 Windows devices in one local network. One - client (that will connect via RDP to second one). Second - "remote desktop" (where we will use AIR application).

  1. Launch code below on "remote desktop" Windows device. It will start to play video in a loop.
  2. If you were not connected at step 1 via RDP to remote desktop when start AIR application then connect via RDP from client computer to remote desktop (where AIR application started).
  3. Close RDP session (disconnect from it).
    *sometimes you should repeat steps 2 and 3 few times to reproduce issue.

Application example with sources and examples of videos attached.
rdp_video_bug.zip

package {
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.net.NetConnection;
	import flash.net.NetStream;
	import flash.media.Video;
	import flash.events.NetStatusEvent;
	import flash.desktop.NativeApplication;
	import flash.desktop.SystemIdleMode;
	
	public class RDPVideoBug extends Sprite {
		private var nc:NetConnection;
		private var ns:NetStream;
		private var video:Video = new Video(640, 480);
		
		public function RDPVideoBug() {
			addEventListener(Event.ADDED_TO_STAGE, init);
		}
		
		private function init(e:Event):void {
			removeEventListener(Event.ADDED_TO_STAGE, init);
			
			addChild(video);
			
			nc = new NetConnection();
			nc.addEventListener(NetStatusEvent.NET_STATUS, ncHandler);
			nc.connect(null);
		}
		

		private function ncHandler(e:NetStatusEvent):void {
			if (e.info.code == "NetConnection.Connect.Success"){
				ns = new NetStream(nc);
				ns.client = {onMetaData:getMeta};
				ns.addEventListener(NetStatusEvent.NET_STATUS, nsHandler);
				video.attachNetStream(ns);
				ns.play("video.mp4");//For AIR 33 use video0.mp4 cause only videos without audio works with AIR 33 right now!
			}
		}

		private function nsHandler(e:NetStatusEvent):void {
			trace(e.info.code);
			if (e.info.code == "NetStream.Play.Stop"){
				ns.play("video.mp4");//For AIR 33 use video0.mp4 cause only videos without audio works with AIR 33 right now!
			}
		}

		private function getMeta(mdata:Object):void { }
		
	}
}

Actual Result:
You will not hear sound anymore (if you use AIR 32 and video that contains audio). Video rendering stop (one frame freeze) or "empty" frame showed (stage color) instead of video but NetStatusEvent.NET_STATUS continue dispatch NetStream.Play.Start, NetStream.Buffer.Full and other "correct" events.
Even after RDP session closed video playback functionality will be broken.

Expected Result:
Depends on RDP connection audio settings ("Remote audio playback").
After RDP connection with "Play on this computer" you should hear sound (if video contains audio) on client computer (where RDP connection initiated) and video rendering should continue correctly.
After RDP connection with "Do not play" you shouldn't hear sound anywhere - it's ok because no audio devices left on remote desktop computer. But video rendering should continue correctly.
After RDP connection with "Play on remote computer" you should continue to hear sound on remote desktop (computer) and video rendering should continue correctly..

After RDP session disconnect you should hear sound again and see video rendering correctly on remote desktop (computer) as before.

Known Workarounds

none

@itlancer
Copy link
Author

Issue still exists using AIR 50.2.2.4. With some devices/videos/audios it happens only in ~30% of attempts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants