/// <summary>Set URL of a media resource. Return a task which completes when it’s ready to be played, or fails if it was unable to do so.</summary> public static Task loadMedia(this iMediaEngine mediaEngine, string url) { if (mediaEngine is iLinuxMediaEngine linux) { // Linux implementation is in .NET, it exposes a task-based asynchronous API for loading videos return(linux.loadMedia(url)); } // Windows implementation is in C++, needs that helper iCompletionSource object to marshal the result back to .NET CompletionSource cs = new CompletionSource(); mediaEngine.loadMedia(url, cs); return(cs.task); }
async Task iSceneAsyncInit.createResourcesAsync(Context context) { iDiligentWindow wnd = context.renderContext as iDiligentWindow; wnd?.setTitle("Vrmac graphics video player sample"); mediaEngine.autoPlay = true; // string dir = RuntimeEnvironment.runningWindows ? windowsDirectory : linuxDirectory; // await mediaEngine.loadMedia( Path.Combine( dir, fileName ) ); await mediaEngine.loadMedia(mediaFilePath); var streams = mediaEngine.mediaStreams; if (!streams.HasFlag(eMediaStreams.Video)) { throw new ApplicationException("There's no video in that media file"); } using (var dev = context.device) renderState = mediaEngine.createRenderer(context, dev, videoBorderColor); context.swapChainResized.add(this, onResized); ConsoleLogger.logInfo("VideoPlayerSample started playing the media"); mouseHandler.subscribe(controller); controller.initialize(animation, mediaEngine); if (null != wnd) { string fileName = Path.GetFileName(mediaFilePath); wnd.windowTitle = "Vrmac graphics video player sample: " + fileName; } // Debug code below: wait 2 seconds, and seek // await Task.Delay( 2000 ); // mediaEngine.setCurrentTime( TimeSpan.FromSeconds( 2278 ) ); }