public void NextFrame() { lock (_lock) { if (mp == IntPtr.Zero) { return; } VLC.libvlc_media_player_next_frame(mp); } }
public void AudioTrack(int which) { lock (_lock) { if (mp == IntPtr.Zero) { return; } VLC.libvlc_audio_set_track(mp, which); } }
public void Subtitle(int which) { lock (_lock) { if (mp == IntPtr.Zero) { return; } VLC.libvlc_video_set_spu(mp, which); } }
public void Seek(ulong ms) { lock (_lock) { if (mp == IntPtr.Zero) { return; } VLC.libvlc_media_player_set_time(mp, ms); } }
public void TogglePause() { lock (_lock) { if (mp == IntPtr.Zero) { return; } VLC.libvlc_media_player_pause(mp); } }
public void Play(string path) { if (File.Exists(path)) { lock (_lock) { IntPtr m = VLC.libvlc_media_new_path(vlc, path); mp = VLC.libvlc_media_player_new_from_media(m); VLC.libvlc_media_player_play(mp); } } else { Stop(); } }
public Server(NSObject app) { _app = app; string[] args = new string[] { // "-vvvvv", "--no-xlib", }; vlc = VLC.libvlc_new(args.Length, args); _timer = NSTimer.CreateRepeatingTimer(0.1, ev_timer); NSRunLoop.Current.AddTimer(_timer, NSRunLoop.NSRunLoopCommonModes); TcpListener tcpListener = new TcpListener(IPAddress.Any, 4357); (new Thread(delegate() { tcpListener.Start(); while (true) { try { Client c = new Client(this, tcpListener.AcceptTcpClient()); lock (_lock) { if (mp != IntPtr.Zero) { c.Send(_playing ? "*playing" : "*paused"); c.Send(_seekable ? "*seekable" : "*notseekable"); c.Send("*audiotrack " + _audiotrack); c.Send("*audiotrackcount " + _audiotrackcount); c.Send("*subtitle " + _subtitle); c.Send("*subtitlecount " + _subtitlecount); c.Send("*time " + _time); c.Send("*length " + _length); } } } catch (Exception e) { Console.WriteLine("error creating client: " + e.ToString()); } } }) { IsBackground = true }).Start(); }
void ev_timer() { lock (_lock) { if (mp == IntPtr.Zero) { return; } bool playing = false; switch (VLC.libvlc_media_player_get_state(mp)) { case VLC.State.NothingSpecial: return; case VLC.State.Opening: return; case VLC.State.Buffering: return; case VLC.State.Playing: playing = true; break; case VLC.State.Paused: playing = false; break; case VLC.State.Stopped: // Console.WriteLine("STOPPED"); NSApplication.SharedApplication.Terminate(_app); return; case VLC.State.Ended: Client.Broadcast("*ended"); Thread.Sleep(500); NSApplication.SharedApplication.Terminate(_app); return; case VLC.State.Error: NSApplication.SharedApplication.Terminate(_app); return; default: NSApplication.SharedApplication.Terminate(_app); return; } // Console.WriteLine("timer"); NSCursor.SetHiddenUntilMouseMoves(true); bool force = firsttimer; firsttimer = false; if (_playing != playing || force) { _playing = playing; if (_playing) { VLC.libvlc_set_fullscreen(mp, true); } Client.Broadcast(_playing ? "*playing" : "*paused"); } bool seekable = VLC.libvlc_media_player_is_seekable(mp); if (_seekable != seekable || force) { _seekable = seekable; Client.Broadcast(_seekable ? "*seekable" : "*notseekable"); } int audiotrack = VLC.libvlc_audio_get_track(mp); if (_audiotrack != audiotrack || force) { _audiotrack = audiotrack; Client.Broadcast("*audiotrack " + _audiotrack); } int audiotrackcount = VLC.libvlc_audio_get_track_count(mp); if (_audiotrackcount != audiotrackcount || force) { _audiotrackcount = audiotrackcount; Client.Broadcast("*audiotrackcount " + _audiotrackcount); } int subtitle = VLC.libvlc_video_get_spu(mp); if (_subtitle != subtitle || force) { _subtitle = subtitle; Client.Broadcast("*subtitle " + _subtitle); } int subtitlecount = VLC.libvlc_video_get_spu_count(mp); if (_subtitlecount != subtitlecount || force) { _subtitlecount = subtitlecount; Client.Broadcast("*subtitlecount " + _subtitlecount); } ulong time = VLC.libvlc_media_player_get_time(mp); if (_time != time || force) { _time = time; Client.Broadcast("*time " + _time); } ulong length = VLC.libvlc_media_player_get_length(mp); if (_length != length || force) { _length = length; Client.Broadcast("*length " + _length); } // Console.WriteLine("donetimer"); } }