bool IPlaybackController.Initialized(IPlaybackSession playbackSession) { IPlaybackController playbackController = null; lock (syn) { if (this.playbackController == null) { return(false); } playbackController = this.playbackController; dbg.Assert(this.playbackSession == null); } var result = playbackController.Initialized(playbackSession); lock (syn) { if (this.playbackController == null) { return(false); } dbg.Assert(this.playbackSession == null); if (result) { this.playbackSession = playbackSession; } return(result); } }
public void Initialize(ITrackController trackController, IPlaybackController playbackController) { this.trackController = trackController; this.playbackController = playbackController; playButtonImage.DataContext = playbackController.Status; }
protected virtual void Dispose(bool disposing) { if (disposing) { IPlaybackController playbackController = null; IPlaybackSession playbackSession = null; lock (syn) { playbackSession = this.playbackSession; playbackController = this.playbackController; this.playbackController = null; this.playbackSession = null; } if (playbackController != null) { playbackController.Shutdown(); } if (playbackSession != null) { try { playbackSession.Close(); } catch (Exception err) { dbg.Error(err); } } } }
public MixViewModelFactory(IPlaybackController playbackController, IMediaLibraryBrowser mediaLibraryBrowser, IObservable <bool> userLoggedInObservable) { this.playbackController = playbackController; this.mediaLibraryBrowser = mediaLibraryBrowser; this.userLoggedInObservable = userLoggedInObservable; }
public SongList(string songListFile, Configuration configuration, IPlaybackController controller, IResourceLoader loader) { this.configuration = configuration; this.controller = controller; this.loader = loader; ParseSongs(songListFile); }
private static PlayerViewModel MakePlayerViewModel(IPlaybackController controller) { // TODO(@MattWindsor91): Autofac should be doing this. var transport = new PlayerTransportViewModel(controller, RxApp.MainThreadScheduler); var markers = new PlayerMarkerViewModel(controller); var track = new PlayerTrackViewModel(controller); var player = new PlayerViewModel(transport, markers, track); return(player); }
public void SetUp() { origSched = RxApp.DeferredScheduler; RxApp.DeferredScheduler = new TestScheduler(); audioPlayer = new AudioPlayerStub(); aMix = new Mix(new MixElement(), 0); requestExecutor = new RequestExecutorStub(); playbackController = new PlaybackController(audioPlayer, requestExecutor); playbackController.CurrentMixObservable.Subscribe(mix => currentMix = mix); }
public MainWindowViewModel(IPlaybackController playbackController, IMediaLibraryBrowser mediaLibraryBrowser, IAuthenticator authenticator, Settings settings) { LoginFormViewModel = new LoginFormViewModel(authenticator); LoginFormViewModel.UserDataObservable.Subscribe( userData => mediaLibraryBrowser.UserToken = userData.UserToken); IMixViewModelFactory mixViewModelFactory = new MixViewModelFactory(playbackController, mediaLibraryBrowser, LoginFormViewModel.UserLoggedInObservable); this.MediaBrowserViewModel = new MediaBrowserViewModel(mediaLibraryBrowser, settings, LoginFormViewModel, mixViewModelFactory); this.PlaybackViewModel = new PlaybackViewModel(playbackController, settings, mixViewModelFactory); new TrackReporter(playbackController.CurrentMixObservable, playbackController.CurrentPositionObservable); }
bool IPlaybackController.Initialized(IPlaybackSession playbackSession) { IPlaybackController playbackController = null; lock (syn) { if (this.playbackController == null) { return false; } playbackController = this.playbackController; dbg.Assert(this.playbackSession == null); } var result = playbackController.Initialized(playbackSession); lock (syn) { if (this.playbackController == null) { return false; } dbg.Assert(this.playbackSession == null); if (result) { this.playbackSession = playbackSession; } return result; } }
public MixViewModel(Mix mixModel, IPlaybackController playbackController, IMediaLibraryBrowser mediaLibraryBrowser, IObservable <bool> userLoggedInObservable) { mixModel.CurrentTrackIndexObservable.Subscribe(x => { // if we're playing a track that has already been added CurrentTrackIndex = x; UpdateCurrentTrackIndicator(); }); mixModel.LikedByCurrentUserObservable.Subscribe(x => LikedByCurrentUser = x); this.Model = mixModel; Play = ReactiveCommand.Create(_ => true); Play.Subscribe(_ => playbackController.Play(Model)); ToggleLike = Model != Mix.NoMixAvailable ? new ReactiveAsyncCommand(userLoggedInObservable, 1) : new ReactiveAsyncCommand(Observable.Return(false), 1); ToggleLike.RegisterAsyncAction(_ => mediaLibraryBrowser.ToggleLike(Model)); this.isUserRequested = ConfigurationManager.AppSettings["AudioPlayer"] == null || !ConfigurationManager.AppSettings["AudioPlayer"].Equals("DirectX WMI 3.14169"); ReplaySubject <bool> skippingSongAllowed = new ReplaySubject <bool>(1); //skipping not allowed if there are no tracks in the mix Model.CurrentTrackIndexObservable.Select(trackIndex => trackIndex < Model.Tracks.Count && trackIndex >= 0 ? Model.Tracks[trackIndex].IsSkipAllowed : false).Subscribe(skippingSongAllowed.OnNext); NextSong = new ReactiveAsyncCommand(skippingSongAllowed, 1); NextSong.RegisterAsyncAction(_ => { try { playbackController.NextSong(isUserRequested); } catch (Exception e) { log.Error("Unable to go to the next song", e); } }); Tracks = new DispatchedReactiveCollection <TrackViewModel>(); // merge current items and future ones Observable.Merge(Model.Tracks.ToObservable(), Model.Tracks.ItemsAdded) .Select(CreateTrackViewModel) .Subscribe(trackViewModel => { Tracks.Add(trackViewModel); UpdateCurrentTrackIndicator(); }); Download = ReactiveCommand.Create(_ => Model != Mix.NoMixAvailable); Download.Subscribe(_ => { string destinationFolder = FileSystemBrowser.GetSaveToDirectory(); if (String.IsNullOrEmpty(destinationFolder)) { return; } destinationFolder += Path.DirectorySeparatorChar + Model.Name; FileSystemBrowser.TryCreateDirectory(destinationFolder); Tracks // .Where( // trackViewModel => // trackViewModel.TrackLocation.Equals(FileLocation.Online.ToString())) .ToObservable() .Subscribe(trackViewModel => SaveTrack(trackViewModel, destinationFolder)); }); FileSystemBrowser = new FileSystemBrowser(); WebAccessProxy = new WebAccessProxy(); // _TotalNumberOfTracks = Tracks.CollectionCountChanged // .ToProperty(this, x => x.TotalNumberOfTracks); CurrentTrackIndexAsString = "0"; skippingSongAllowed.OnNext(false); }
public PlayerHost(PlayerTask playerTask) { playbackController = playerTask.playbackController; playerTask.playbackController = this; this.playerTask = playerTask; }
public IDisposable Play(MediaStreamInfo mediaStreamInfo, IPlaybackController playbackController) { //fix url var url = new Uri(mediaStreamInfo.url); if (url == null || !url.IsAbsoluteUri) { throw new Exception("Invalid playback url"); } if (mediaStreamInfo.transport != MediaStreamInfo.Transport.Http) { if (String.Compare(url.Scheme, "rtsp", true) != 0) { throw new Exception("Invalid playback url"); } } else if (String.Compare(url.Scheme, "rtsp", true) != 0) { int defPort; if (String.Compare(url.Scheme, Uri.UriSchemeHttp, true) == 0) { defPort = 80; } else if (String.Compare(url.Scheme, Uri.UriSchemeHttps, true) == 0) { defPort = 443; } else { throw new Exception("Invalid playback url"); } var ub = new UriBuilder(url); ub.Scheme = "rtsp"; if (ub.Port == -1) { ub.Port = defPort; } url = ub.Uri; mediaStreamInfo = new MediaStreamInfo(url.ToString(), mediaStreamInfo.transport, mediaStreamInfo.userNameToken); } var disposable = new SingleAssignmentDisposable(); playerTask.mediaStreamInfo = mediaStreamInfo; playerTask.playbackController = playbackController; if (playerHost != null) { playerHost.Dispose(); RemotingServices.Disconnect(playerHost); playerHost = null; } playerHost = new PlayerHost(playerTask); RemotingServices.Marshal(playerHost); var ipcChannel = AppHosting.SetupChannel(); var hostControllerUri = RemotingServices.GetObjectUri(playerHost); var hostControllerUrl = ipcChannel.GetUrlsForUri(hostControllerUri).First(); //start player host process var hostProcessArgs = new CommandLineArgs(); var t = Uri.EscapeDataString(hostControllerUrl); hostProcessArgs.Add("controller-url", new List <string> { hostControllerUrl }); var pi = new ProcessStartInfo() { FileName = Assembly.GetExecutingAssembly().Location, UseShellExecute = false, Arguments = String.Join(" ", hostProcessArgs.Format()), }; pi.EnvironmentVariables["PATH"] = String.Join("; ", Bootstrapper.specialFolders.dlls.Select(sfd => sfd.directory.FullName).Append(pi.EnvironmentVariables["PATH"])); StartHostProcess(pi); return(Disposable.Create(() => { Dispose(); })); }
public SongList(string songListFile, IPlaybackController controller, IPlaybackController controllerCustom) { this.controller = controller; this.controllerCustom = controllerCustom; ParseSongs(songListFile); }
public void Resume(Item item) { if (item.IsPlayable) { currentPlaybackController = item.PlaybackController; //async this so it doesn't slow us down if the service isn't responding for some reason MediaBrowser.Library.Threading.Async.Queue("Cancel Svc Refresh", () => { MBServiceController.SendCommandToService(IPCCommands.CancelRefresh); //tell service to stop }); //put this on a thread so that we can run it sychronously, but not tie up the UI MediaBrowser.Library.Threading.Async.Queue("Resume Action", () => { if (Application.CurrentInstance.RunPrePlayProcesses(item, false)) { item.Resume(); this.lastPlayed = item; } }); } }
public void PlayLocalTrailer(Item item, bool fullScreen) { if (!String.IsNullOrEmpty(item.TrailerPath)) { currentPlaybackController = item.PlaybackController; currentPlaybackController.PlayMedia(item.TrailerPath); if (fullScreen) currentPlaybackController.GoToFullScreen(); } }
public PlaybackViewModel(IPlaybackController playbackController, Settings settings, IMixViewModelFactory mixViewModelFactory) { this.playbackController = playbackController; this.settings = settings; var volumeString = (string)settings[volumeKey] ?? "50"; Volume = Double.Parse(volumeString); _CurrentPosition = playbackController.CurrentPositionObservable .ToProperty(this, x => x.CurrentPosition); _CurrentPositionAsString = playbackController.CurrentPositionObservable .Select(TimeSpan.FromSeconds) .Select(DurationToString) .ToProperty(this, x => x.CurrentPositionAsString); // connecting current mix being played to the viewmodel IObservable <MixViewModel> currentMixViewModelObservable = playbackController.CurrentMixObservable.Select(mixViewModelFactory.CreateMixViewModel); _CurrentMixViewModel = currentMixViewModelObservable .ToProperty(this, x => x.CurrentMixViewModel); IObservable <bool> _CurrentMixViewModelPresent = this.WhenAny( x => x.CurrentMixViewModel, mixViewModel => mixViewModel.Value != null && mixViewModel.Value.Model != Mix.NoMixAvailable); _CurrentTrackDurationAsString = playbackController.CurrentDurationObservable .Select(duration => DurationToString(TimeSpan.FromSeconds(duration))) .ToProperty(this, x => x.CurrentTrackDurationAsString); _CurrentTrackDuration = playbackController.CurrentDurationObservable .ToProperty(this, x => x.CurrentTrackDuration); // commands // going to the next song only if there is a mix currently loaded _NextSong = currentMixViewModelObservable .Select(x => x.NextSong) .ToProperty(this, x => x.NextSong); var audioPlayerState = playbackController.PlayerStateObservable; // both having a current mix and not running var audioPlayerNotRunning = audioPlayerState.Select(status => status == MediaStatus.Stopped || status == MediaStatus.Paused).CombineLatest( _CurrentMixViewModelPresent, (x, y) => x && y); Continue = new ReactiveAsyncCommand(audioPlayerNotRunning, 1); Continue.Subscribe(_ => playbackController.Continue()); var audioPlayerRunning = audioPlayerState.Select(status => status == MediaStatus.Running); Pause = new ReactiveAsyncCommand(audioPlayerRunning, 1); Pause.Subscribe(_ => playbackController.Pause()); var audioPlayerRunningOrPaused = audioPlayerState.Select(status => status == MediaStatus.Running || status == MediaStatus.Paused); Stop = new ReactiveAsyncCommand(audioPlayerRunningOrPaused, 1); Stop.Subscribe(_ => playbackController.Stop()); NextMix = new ReactiveAsyncCommand(_CurrentMixViewModelPresent, 1); NextMix.RegisterAsyncAction(_ => { try { playbackController.NextMix(); } catch (Exception e) { log.Error("Unable to go to the next mix", e); } } ); bool debugModeOn = ConfigurationManager.AppSettings["AudioPlayer"] != null && ConfigurationManager.AppSettings["AudioPlayer"].Equals("DirectX WMI 3.14169"); _IsPositionSliderEnabled = audioPlayerRunningOrPaused .Select(a => a && debugModeOn) .ToProperty(this, x => x.IsPositionSliderEnabled); GoToTrack = new ReactiveAsyncCommand(_CurrentMixViewModelPresent, 1); GoToTrack.Subscribe(_ => { if (debugModeOn) { try { playbackController.GoToTrack(SelectedTrackIndex); } catch (Exception e) { log.Error("Unable to go to track " + SelectedTrackIndex, e); } } }); Skip = new ReactiveAsyncCommand(audioPlayerRunningOrPaused, 1); Skip.Subscribe(step => { double newPosition = CurrentPosition + Double.Parse((string)step); if (newPosition >= 0 && newPosition <= CurrentTrackDuration) { CurrentPosition = newPosition; } }); ChangeVolume = new ReactiveAsyncCommand(null, 1); ChangeVolume.Subscribe(step => { double newVolume = Volume + Double.Parse((string)step); if (newVolume >= 0 && newVolume <= 100) { Volume = newVolume; } }); }
public MediaRemoteControl(IPlaybackController playbackController) { _playbackController = playbackController; }
public IDisposable Play(MediaStreamInfo mediaStreamInfo, IPlaybackController playbackController) { //fix url var url = new Uri(mediaStreamInfo.url); if (url == null || !url.IsAbsoluteUri) { throw new Exception("Invalid playback url"); } if (mediaStreamInfo.transport != MediaStreamInfo.Transport.Http) { if (String.Compare(url.Scheme, "rtsp", true) != 0) { throw new Exception("Invalid playback url"); } } else if (String.Compare(url.Scheme, "rtsp", true) != 0) { int defPort; if (String.Compare(url.Scheme, Uri.UriSchemeHttp, true) == 0) { defPort = 80; } else if (String.Compare(url.Scheme, Uri.UriSchemeHttps, true) == 0) { defPort = 443; } else { throw new Exception("Invalid playback url"); } var ub = new UriBuilder(url); ub.Scheme = "rtsp"; if (ub.Port == -1) { ub.Port = defPort; } url = ub.Uri; mediaStreamInfo = new MediaStreamInfo(url.ToString(), mediaStreamInfo.transport, mediaStreamInfo.userNameToken); } var disposable = new SingleAssignmentDisposable(); playerTask.mediaStreamInfo = mediaStreamInfo; playerTask.playbackController = playbackController; if (playerHost != null) { playerHost.Dispose(); RemotingServices.Disconnect(playerHost); playerHost = null; } playerHost = new PlayerHost(playerTask); RemotingServices.Marshal(playerHost); var ipcChannel = AppHosting.SetupChannel(); var hostControllerUri = RemotingServices.GetObjectUri(playerHost); var hostControllerUrl = ipcChannel.GetUrlsForUri(hostControllerUri).First(); //start player host process var hostProcessArgs = new CommandLineArgs(); var t = Uri.EscapeDataString(hostControllerUrl); hostProcessArgs.Add("controller-url", new List<string> { hostControllerUrl }); var pi = new ProcessStartInfo() { FileName = Assembly.GetExecutingAssembly().Location, UseShellExecute = false, Arguments = String.Join(" ", hostProcessArgs.Format()), }; pi.EnvironmentVariables["PATH"] = String.Join("; ", Bootstrapper.specialFolders.dlls.Select(sfd => sfd.directory.FullName).Append(pi.EnvironmentVariables["PATH"])); StartHostProcess(pi); return Disposable.Create(() => { Dispose(); }); }
public void Play(Item item, bool queue, bool intros) { if (item.IsPlayable || item.IsFolder) { currentPlaybackController = item.PlaybackController; if (queue) item.Queue(); else { //async this so it doesn't slow us down if the service isn't responding for some reason MediaBrowser.Library.Threading.Async.Queue("Cancel Svc Refresh", () => { MBServiceController.SendCommandToService(IPCCommands.CancelRefresh); //tell service to stop }); //put this on a thread so that we can run it sychronously, but not tie up the UI MediaBrowser.Library.Threading.Async.Queue("Play Action", () => { if (Application.CurrentInstance.RunPrePlayProcesses(item, intros)) { item.Play(); this.lastPlayed = item; } else { //be sure we run finished process if (item.PlayableItem.OnPlayBackFinished != null) item.PlayableItem.OnPlayBackFinished(true); } }); } } }