/// <summary> /// Handles incoming websocket events, acts accordingly. /// </summary> /// <param name="sender"></param> /// <param name="response"></param> private void WebSocketDataRecieved(object sender, RoomSocket response) { switch (response.message) { // The user has been added to the room case "allocation": webSocketService.token = response.token; webSocketService.roomId = response.room; GetRoomMedia(); break; // There is a change in the state of the media case "mediaChange": Room.CurrentMedia = response.media; MediaChanged?.Invoke(this, new EventArgs()); break; // A message from a user, that was broadcasted to the room is recieved case "message": Room.AddMessage(response.messageData); MessageRecieved?.Invoke(this, new EventArgs()); break; default: break; } }
/// <summary> /// Loads the specified file into the player. /// </summary> /// <param name="fileName">Path to the music file.</param> /// <returns>Boolean</returns> public async Task <bool> Load(Mediafile mediaFile) { if (mediaFile != null && mediaFile.Length != "00:00") { try { string path = mediaFile.Path; await InitializeCore.Dispatcher.RunAsync(() => { MediaChanging?.Invoke(this, new EventArgs()); }); await Stop(); await Task.Run(() => { _handle = Bass.CreateStream(path, 0, 0, BassFlags.AutoFree | BassFlags.Float); PlayerState = PlayerState.Stopped; Length = 0; Length = Bass.ChannelBytes2Seconds(_handle, Bass.ChannelGetLength(_handle)); Bass.FloatingPointDSP = true; Bass.ChannelSetDevice(_handle, 1); Bass.ChannelSetSync(_handle, SyncFlags.End | SyncFlags.Mixtime, 0, _sync); Bass.ChannelSetSync(_handle, SyncFlags.Position, Bass.ChannelSeconds2Bytes(_handle, Length - 5), _posSync); Bass.ChannelSetSync(_handle, SyncFlags.Position, Bass.ChannelSeconds2Bytes(_handle, Length - 15), _posSync); CurrentlyPlayingFile = mediaFile; }); if (Equalizer == null) { Equalizer = new BassEqualizer(_handle); } else { (Equalizer as BassEqualizer).ReInit(_handle); } MediaStateChanged?.Invoke(this, new MediaStateChangedEventArgs(PlayerState.Stopped)); MediaChanged?.Invoke(this, new EventArgs()); return(true); } catch (Exception ex) { await InitializeCore.NotificationManager.ShowMessageAsync(ex.Message + "||" + mediaFile.OrginalFilename); } } else { string error = "The file " + mediaFile?.OrginalFilename + " is either corrupt, incomplete or unavailable. \r\n\r\n Exception details: No data available."; if (IgnoreErrors) { await InitializeCore.NotificationManager.ShowMessageAsync(error); } else { await InitializeCore.NotificationManager.ShowMessageBoxAsync(error, "File corrupt"); } } return(false); }
public async Task <bool> LoadURLAsync(Mediafile mediafile, string uri) { if (string.IsNullOrEmpty(uri)) { return(false); } return(await LoadMusicAsync(() => { int metaSize = 1024 * 200; //1MB MemoryStream metadataStream = new MemoryStream(); BinaryWriter bw = new BinaryWriter(metadataStream); bool done = false; CurrentlyPlayingFile = mediafile; _handle = Bass.CreateStream(uri, 0, BassFlags.Default | BassFlags.Float | BassFlags.AutoFree, new DownloadProcedure((buffer, length, user) => { if (done) { return; //we are done here. } if (metadataStream.Length <= metaSize) { unsafe { // simply cast the given IntPtr to a native pointer to short values // assuming you receive 16-bit sample data here short *data = (short *)buffer; for (int a = 0; a < length / 2; a++) { // write the received sample data to a local file bw.Write(data[a]); } } } else { //there are HTTP Headers in the start of the recieved stream. //we need to skip those so that we can parse ID3 tags. //HTTP HEADER Removal START var array = metadataStream.ToArray(); string str = Encoding.UTF8.GetString(array); int l = str.IndexOf("ID3"); string headers = str.Substring(0, l); byte[] id3TagArray = new byte[array.Length - l]; Buffer.BlockCopy(array, l, id3TagArray, 0, id3TagArray.Length); //HTTP HEADER Removal END var h = StringToHttpHeaders(headers); ID3TagParser.WriteTagsToMediafile(mediafile, array, Length); CurrentlyPlayingFile = mediafile; MediaChanged?.Invoke(this, new EventArgs()); done = true; metadataStream.Dispose(); bw.Dispose(); } })); })); }
internal void PostMediaChangedEvent(MediaInfo mediaInfo) { LogEventStart(nameof(MediaChanged)); Library.GuiContext.EnqueueInvoke(() => { MediaChanged?.Invoke(this, new MediaOpenedEventArgs(mediaInfo)); LogEventDone(nameof(MediaChanged)); }); }
private void OnMediaChanged(uBaseObject old, uBaseObject newMedia) { if (MediaChanged != null) { MediaChanged.Invoke(this, new MediaChangedEventArgs { OldMediaInfo = old, NewMediaInfo = newMedia }); } }
private async void Wv_ContentLoading(WebView sender, WebViewContentLoadingEventArgs args) { var url = await wvMain.InvokeScriptAsync("eval", new string[] { "document.location.href;" }); if (HasUrlBeenProcessed(url)) { return; } lastProcessedUrl = url; MediaChanged?.Invoke(null, new MediaChangedEventArgs() { MediaUri = new Uri(url) }); }
public async Task <bool> LoadStreamAsync(Mediafile mediafile, byte[] array) { if (array?.Length <= 0) { return(false); } return(await LoadMusicAsync(() => { _handle = Bass.CreateStream(array, 0, array.Length, BassFlags.Float); if (mediafile.MediaLocation != MediaLocationType.Local) { ID3TagParser.WriteTagsToMediafile(mediafile, array, Length); CurrentlyPlayingFile = mediafile; MediaChanged?.Invoke(this, new EventArgs()); } })); }
public async Task <bool> LoadLocalFileAsync(Mediafile mediaFile) { if ((mediaFile != null && mediaFile.Length != "00:00")) { return(await LoadMusicAsync(() => { _handle = Bass.CreateStream(mediaFile.Path, 0, 0, BassFlags.AutoFree | BassFlags.Float); CurrentlyPlayingFile = mediaFile; MediaChanged?.Invoke(this, new EventArgs()); })); } else { string error = "The file " + mediaFile?.OrginalFilename + " is either corrupt, incomplete or unavailable. \r\n\r\n Exception details: No data available."; await InitializeSwitch.NotificationManager.ShowMessageAsync(error); return(false); } }
protected virtual void OnMediaChanged(CurrentMediaChangedEventArgs e) { MediaChanged?.Invoke(this, e); }
public void OnMediaPlayerMediaChanged(VlcMedia media) { MediaChanged?.Invoke(this, new VlcMediaPlayerMediaChangedEventArgs(media)); }