/// <summary> /// Stop the conversation between callers. /// </summary> /// <param name="caller">The caller to stop the conversation with.</param> public void StopConversation(CallParam caller) { // Combine the audio media. List <AudioMedia> local = new List <AudioMedia>(); local.AddRange(_audioMedias); local.AddRange(caller.AudioMedia); // For each call. for (int i = 0; i < local.Count; i++) { // Get first group. AudioMedia mediaCall_1 = local[i]; // For each call. for (int j = 0; j < local.Count; j++) { // Get second group. AudioMedia mediaCall_2 = local[j]; // If the two audio media are not equal. if (mediaCall_1.GetPortId() != mediaCall_2.GetPortId()) { // Stop these two calls from communicating. mediaCall_1.StopTransmit(mediaCall_2); } } } }
public static AudioMediaRecorder typecastFromAudioMedia(AudioMedia media) { global::System.IntPtr cPtr = pjsua2PINVOKE.AudioMediaRecorder_typecastFromAudioMedia(AudioMedia.getCPtr(media)); AudioMediaRecorder ret = (cPtr == global::System.IntPtr.Zero) ? null : new AudioMediaRecorder(cPtr, false); return(ret); }
public void startTransmit2(AudioMedia sink, AudioMediaTransmitParam param) { pjsua2PINVOKE.AudioMedia_startTransmit2(swigCPtr, AudioMedia.getCPtr(sink), AudioMediaTransmitParam.getCPtr(param)); if (pjsua2PINVOKE.SWIGPendingException.Pending) { throw pjsua2PINVOKE.SWIGPendingException.Retrieve(); } }
public void stopTransmit(AudioMedia sink) { pjsua2PINVOKE.AudioMedia_stopTransmit(swigCPtr, AudioMedia.getCPtr(sink)); if (pjsua2PINVOKE.SWIGPendingException.Pending) { throw pjsua2PINVOKE.SWIGPendingException.Retrieve(); } }
public void mediaRemove(AudioMedia media) { pjsua2PINVOKE.Endpoint_mediaRemove(swigCPtr, AudioMedia.getCPtr(media)); if (pjsua2PINVOKE.SWIGPendingException.Pending) { throw pjsua2PINVOKE.SWIGPendingException.Retrieve(); } }
public void FillModel(AudioMedia media) { Title = media.Title; Artist = media.Artist; Album = media.Album; Year = media.Year; Bitrate = media.Bitrate; }
/// <summary> /// Play a sound file to the current caller. /// </summary> /// <param name="filename">The filename and path of the sound file.</param> /// <param name="option">Optional option flag. Application may specify PJMEDIA_FILE_NO_LOOP = 1 to prevent playback loop.</param> public void PlaySoundFile(string filename, uint option = 1) { if (_call != null) { try { List <AudioMedia> audioMedias = new List <AudioMedia>(); // Get the call info CallInfo ci = _call.GetInfo(); if (ci != null) { // Create the player. _player = new AudioMediaPlayer(); _player.OnPlayerEndOfFile += _player_OnPlayerEndOfFile; _player.CreatePlayer(filename, option); // For each media. for (int i = 0; i < ci.Media.Length; i++) { // If objects exist. if (ci.Media != null && ci.Media[i] != null && _call != null) { // If audio type. if ((ci.Media[i].Type == Nequeo.Net.PjSip.MediaType.PJMEDIA_TYPE_AUDIO) && (_call.GetMedia((uint)i) != null)) { // Get the audio media. AudioMedia audioMedia = (AudioMedia)_call.GetMedia((uint)i); audioMedias.Add(audioMedia); } } } } // If created. if (_player != null && audioMedias != null && audioMedias.Count > 0) { // Start playing the file to the caller. _player.Start(audioMedias[0]); } } catch { try { if (_player != null) { _player.Dispose(); } } catch { } _player = null; } } }
public AudioMedia getPlaybackDevMedia() { AudioMedia ret = new AudioMedia(pjsua2PINVOKE.AudDevManager_getPlaybackDevMedia(swigCPtr), false); if (pjsua2PINVOKE.SWIGPendingException.Pending) { throw pjsua2PINVOKE.SWIGPendingException.Retrieve(); } return(ret); }
public bool mediaExists(AudioMedia media) { bool ret = pjsua2PINVOKE.Endpoint_mediaExists(swigCPtr, AudioMedia.getCPtr(media)); if (pjsua2PINVOKE.SWIGPendingException.Pending) { throw pjsua2PINVOKE.SWIGPendingException.Retrieve(); } return(ret); }
public AudioMedia getAudioMedia(int med_idx) { AudioMedia ret = new AudioMedia(pjsua2PINVOKE.Call_getAudioMedia(swigCPtr, med_idx), true); if (pjsua2PINVOKE.SWIGPendingException.Pending) { throw pjsua2PINVOKE.SWIGPendingException.Retrieve(); } return(ret); }
/// <summary> /// Append a new audio asset to the root. /// Set the location and timing of the audio node to that of the asset. /// Set the text in the node to the label of the asset. /// The phrase is added to the list of phrases in that project. /// </summary> /// <param name="asset">The asset to append.</param> public void AppendPhrase(AudioMediaAsset asset) { CoreNode node = this.getPresentation().getCoreNodeFactory().createNode(); ChannelsProperty prop = (ChannelsProperty)node.getProperty(PropertyType.CHANNEL); AudioMedia audio = (AudioMedia)this.getPresentation().getMediaFactory().createMedia(MediaType.AUDIO); audio.setLocation(new MediaLocation(asset.Path)); audio.setClipEnd(new Time((long)Math.Round(asset.LengthInMilliseconds))); prop.setMedia(mAudioChannel, audio); TextMedia text = (TextMedia)this.getPresentation().getMediaFactory().createMedia(MediaType.TEXT); text.setText(asset.Name); prop.setMedia(mTextChannel, text); this.getPresentation().getRootNode().appendChild(node); mPhrases.Add(new Phrase(node, asset)); }
public async Task <IActionResult> GetOne(int id) { try { BaseMedia mediaFile = await _Db.Media.FindAsync(id); ImageMedia imageFile = mediaFile as ImageMedia; AudioMedia audioFile = mediaFile as AudioMedia; if (mediaFile == null) { return(NotFound("No file exists for the supplied ID")); } return(Ok(new { mediaFile.Id, mediaFile.Name, mediaFile.FilePath, mediaFile.Size, mediaFile.MediaType, Source = new { showCopyright = mediaFile.ShowCopyright, info = mediaFile.Source }, fileName = mediaFile.Filename, height = imageFile?.Height, width = imageFile?.Width, versions = imageFile?.Versions, title = imageFile?.Title, alt = imageFile?.Alt, duration = audioFile?.Duration, tags = mediaFile.Tags(), usages = mediaFile.GetUsages(_Db) })); } catch (Exception ex) { _Logger.LogError("Error retrieving file data: {0}", ex.Message); _Logger.LogError(ex.StackTrace); return(BadRequest("Something went wrong, please try again later.")); } }
public AudioMedia getAudioMedia() { lock (locker) { if (State.In(pjsip_inv_state.PJSIP_INV_STATE_NULL, pjsip_inv_state.PJSIP_INV_STATE_DISCONNECTED)) { return(null); } for (var i = 0; i < getInfo().media.Count; ++i) { if (getInfo().media[i].type != pjmedia_type.PJMEDIA_TYPE_AUDIO) { continue; } return(AudioMedia.typecastFromMedia(getMedia((uint)i))); } return(null); } }
public override void onCallMediaState(OnCallMediaStateParam prm) { base.onCallMediaState(prm); var ci = getInfo(); for (uint i = 0; i < ci.media.Count; i++) { if (ci.media[(int)i].type == pjmedia_type.PJMEDIA_TYPE_AUDIO) { var audMed = AudioMedia.typecastFromMedia(this.getMedia(i)); var mgr = Endpoint.instance().audDevManager(); audMed.startTransmit(mgr.getPlaybackDevMedia()); mgr.getCaptureDevMedia().startTransmit(audMed); } else { throw new ApplicationException("现在仅支持音频哦亲"); } } }
/// <summary> /// Stop transmitting media to the caller. /// </summary> public void StopTransmitting() { // Combine the audio media. List <AudioMedia> local = new List <AudioMedia>(); local.AddRange(_audioMedias); // For each call. for (int i = 0; i < local.Count; i++) { // Get first group. AudioMedia audioMedia = local[i]; // Connect the call audio media to sound device. audioMedia.StopTransmit(_mediaManager.GetPlaybackDeviceMedia()); _mediaManager.GetCaptureDeviceMedia().StopTransmit(audioMedia); } // Transmitting. _isTransmitting = false; }
/// <summary> /// Обрабатываем событие изменения статуса медиа /// </summary> /// <param name="prm"></param> public override void onCallMediaState(OnCallMediaStateParam prm) { CallInfo ci = getInfo(); AudioMedia aud_med; try { aud_med = getAudioMedia(-1); } catch { return; } AudDevManager mgr = Endpoint.instance().audDevManager(); AudioMedia play_dev_med = mgr.getPlaybackDevMedia(); aud_med.startTransmit(play_dev_med); AudioMedia cap_aud_med = mgr.getCaptureDevMedia(); cap_aud_med.startTransmit(aud_med); }
private void addSongCmd() { OpenFileDialog dialog = new OpenFileDialog(); bool? res; dialog.Multiselect = true; dialog.Filter = "Audio files|*.mp3;*.wav;*.wma;*.ogg"; res = dialog.ShowDialog(); if (res == true) { foreach (string file in dialog.FileNames) { AudioMedia tmp = Media.CreateMedia(false, file, false, ExtensionStatic.GetIconsFromExtension(Path.GetExtension(file))) as AudioMedia; if (tmp != null) { ListSongs.Add(tmp); } } } saveSongs(); }
internal static global::System.Runtime.InteropServices.HandleRef getCPtr(AudioMedia obj) { return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr); }
public bool mediaExists(AudioMedia media) { bool ret = pjsua2PINVOKE.Endpoint_mediaExists(swigCPtr, AudioMedia.getCPtr(media)); if (pjsua2PINVOKE.SWIGPendingException.Pending) throw pjsua2PINVOKE.SWIGPendingException.Retrieve(); return ret; }
public void mediaRemove(AudioMedia media) { pjsua2PINVOKE.Endpoint_mediaRemove(swigCPtr, AudioMedia.getCPtr(media)); if (pjsua2PINVOKE.SWIGPendingException.Pending) throw pjsua2PINVOKE.SWIGPendingException.Retrieve(); }
internal static global::System.Runtime.InteropServices.HandleRef getCPtr(AudioMedia obj) { return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr; }
public void stopTransmit(AudioMedia sink) { pjsua2PINVOKE.AudioMedia_stopTransmit(swigCPtr, AudioMedia.getCPtr(sink)); if (pjsua2PINVOKE.SWIGPendingException.Pending) throw pjsua2PINVOKE.SWIGPendingException.Retrieve(); }
/// <summary> /// Notify application when call state has changed. /// Application may then query the call info to get the /// detail call states by calling getInfo() function. /// </summary> /// <param name="sender">The current sender.</param> /// <param name="e">The event parameter.</param> private void _call_OnCallState(object sender, OnCallStateParam e) { Nequeo.Net.PjSip.CallInfo ci = e.Info; if (ci != null) { _info = null; try { // Create the call info. _info = new CallInfoParam(); _info.CallID = ci.Id; _info.Guid = _guid; _info.Contact = ci.RemoteContact; _info.FromTo = ci.RemoteUri; _info.Date = DateTime.Now; _info.ConnectDuration = new TimeSpan(0, 0, 0, ci.ConnectDuration.Seconds, ci.ConnectDuration.Milliseconds); _info.TotalDuration = new TimeSpan(0, 0, 0, ci.TotalDuration.Seconds, ci.TotalDuration.Milliseconds); } catch { _info = null; } Param.CallStateParam callState = new CallStateParam(); callState.CallID = ci.Id; callState.State = ci.State; callState.CallInfo = _info; try { // Handle the event. OnCallState?.Invoke(this, callState); // Set the contact name. _info.ContactName = callState.ContactName; } catch { } // If call is disconnected. if ((ci.State == InviteSessionState.PJSIP_INV_STATE_DISCONNECTED) || (ci.State == InviteSessionState.PJSIP_INV_STATE_NULL)) { // If current call. if (e.CurrentCall != null) { try { // Cleanup the call. e.CurrentCall.Dispose(); e.CurrentCall = null; } catch { } } // If recoder. if (_recorder != null) { try { // Stop the recorder. AudioMedia audioMedia = _mediaManager.GetCaptureDeviceMedia(); _recorder.Stop(audioMedia); } catch { } try { // Cleanup the recoder. _recorder.Dispose(); _recorder = null; } catch { } } // If auto answer recoder. if (_recorderAutoAnswer != null) { try { // Cleanup the recoder. _recorderAutoAnswer.Dispose(); _recorderAutoAnswer = null; } catch { } } // If sound player. if (_player != null) { try { // Cleanup the recoder. _player.Dispose(); _player = null; } catch { } } // If video window. if (_videoWindow != null) { try { _hasVideo = false; // Cleanup the video window. _videoWindow.Dispose(); _videoWindow = null; } catch { } } // Cleanup the audio media. if (_audioMedias != null) { _audioMedias.Clear(); _audioMedias = null; } } // If call is disconnected. if ((ci.State == InviteSessionState.PJSIP_INV_STATE_DISCONNECTED) || (ci.State == InviteSessionState.PJSIP_INV_STATE_NULL)) { try { // Handle the event. OnCallDisconnected?.Invoke(this, _info); } catch { } } } }
/// <summary> /// Notify application when media state in the call has changed. /// Normal application would need to implement this callback, e.g. /// to connect the call's media to sound device. When ICE is used, /// this callback will also be called to report ICE negotiation failure. /// </summary> /// <param name="sender">The current sender.</param> /// <param name="e">The event parameter.</param> private void _call_OnCallMediaState(object sender, OnCallMediaStateParam e) { Nequeo.Net.PjSip.CallInfo ci = e.Info; if (ci != null) { // For each media. for (int i = 0; i < ci.Media.Length; i++) { bool recoderSet = false; // If objects exist. if (ci.Media != null && ci.Media[i] != null && e.CurrentCall != null) { // Create the call media param. CallMediaStateParam mediaState = new CallMediaStateParam(); mediaState.Suspend = false; mediaState.CallID = ci.Id; mediaState.CallOnHold = (ci.Media[i].Status == CallMediaStatus.PJSUA_CALL_MEDIA_LOCAL_HOLD ? true : false); mediaState.MediaType = ci.Media[i].Type; // If video type. if (ci.Media[i].Type == Nequeo.Net.PjSip.MediaType.PJMEDIA_TYPE_VIDEO) { _hasVideo = true; _videoWindow = ci.Media[i].VideoWindowEx; mediaState.HasVideo = _hasVideo; _isVideoValid = (ci.Media[i].Direction == MediaDirection.PJMEDIA_DIR_NONE ? false : true); mediaState.IsVideoValid = _isVideoValid; } else { _hasVideo = false; _isVideoValid = false; _videoWindow = null; mediaState.HasVideo = _hasVideo; mediaState.IsVideoValid = _isVideoValid; } // Handle the event. OnCallMediaState?.Invoke(this, mediaState); // If audio type. if ((ci.Media[i].Type == Nequeo.Net.PjSip.MediaType.PJMEDIA_TYPE_AUDIO) && (e.CurrentCall.GetMedia((uint)i) != null)) { // Get the audio media. AudioMedia audioMedia = (AudioMedia)e.CurrentCall.GetMedia((uint)i); _audioMedias.Add(audioMedia); // If not suspend, normal operations. if (!mediaState.Suspend) { // Transmitting. _isTransmitting = true; // Connect the call audio media to sound device. audioMedia.StartTransmit(_mediaManager.GetPlaybackDeviceMedia()); _mediaManager.GetCaptureDeviceMedia().StartTransmit(audioMedia); // If recording. if (!recoderSet && !String.IsNullOrEmpty(_recordFilename)) { // Get the capture audio device. AudioMedia audioMediaRecord = _mediaManager.GetCaptureDeviceMedia(); try { // Create the recorder. _recorder = new AudioMediaRecorder(); _recorder.CreateRecorder(_recordFilename, 0, 0, 0); _recorder.StartRecordingConversation(audioMediaRecord, new AudioMedia[] { audioMedia }); } catch { } // Set one recorder. recoderSet = true; } } } // If video type. if (ci.Media[i].Type == Nequeo.Net.PjSip.MediaType.PJMEDIA_TYPE_VIDEO) { } } } } }
/// <summary> /// Add audio media device to the application. /// </summary> /// <param name="audioMedia">The audio media device.</param> public void AddAudioPlaybackDevice(AudioMedia audioMedia) { _endpoint.Endpoint.AddAudioPlaybackDevice(audioMedia); }
public async Task <IActionResult> Index(IFormCollection request) { try { // Create required directories if not existing EnsureInit(); // Deserialize cropping data if applicable CropData cropData = null; if (request.Str("cropData") != null) { cropData = JsonConvert.DeserializeObject <CropData>(request.Str("cropData")); } // Original filename string uploadedName = request.Str("filename"); // Generate a backend filename for the uploaded file - same extension as uploaded file. string filename = Guid.NewGuid().ToString() + Path.GetExtension(uploadedName); string fileType = request.Str("fileType"); // Determine what type of file has been uploaded and act accordingly (may want to refactor these) // FOR IMAGES if (MediaType.MimesForCategory(MediaCategory.Image).Contains(fileType)) { string filepath = Path.Combine("Storage", "Media", "Images", filename); // Save image and all associated versions of it. var filedata = ImageUtils.SaveImage(request.Str("file") .Split(',')[1], filepath, cropData); // Create database record to track images ImageMedia dbImageMedia = new ImageMedia { Name = Path.GetFileNameWithoutExtension(uploadedName), MediaType = MediaType.FromString(fileType), FilePath = filepath, Size = filedata["size"], Title = request.Str("title"), Alt = request.Str("alt"), Width = filedata["width"], Height = filedata["height"], Versions = filedata["versions"] }; await _Db.AddAsync(dbImageMedia); } // FOR AUDIO else if (MediaType.MimesForCategory(MediaCategory.Audio).Contains(fileType)) { string filepath = Path.Combine("Storage", "Media", "Audio", filename); // Save the audio file byte[] bytes = request.Str("file").Split(',')[1].DecodeBase64Bytes(); await System.IO.File.WriteAllBytesAsync(filepath, bytes); // Read the audio file to determine its duration - it will either be mp3(mpeg) or wav // Configure ffprobe path using appsettings values FFProbe probe = new FFProbe(); probe.ToolPath = _Config["ffprobePath"]; // If running linux, look for ffprobe instaed of ffprobe.exe if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { probe.FFProbeExeName = "ffprobe"; } // Get audio file metadata MediaInfo mediaInfo = probe.GetMediaInfo(Path.Combine(_HostingEnv.ContentRootPath, filepath)); // Create the media database record AudioMedia audioMedia = new AudioMedia { Name = Path.GetFileNameWithoutExtension(uploadedName), MediaType = MediaType.FromString(fileType), FilePath = filepath, Size = new FileInfo(filepath).Length, Duration = Math.Round(mediaInfo.Duration.TotalSeconds) }; await _Db.AddAsync(audioMedia); } // FOR GENERAL else if (MediaType.MimesForCategory(MediaCategory.General).Contains(fileType)) { string filepath = Path.Combine("Storage", "Media", "Documents", filename); // Save the file byte[] bytes = request.Str("file").Split(',')[1].DecodeBase64Bytes(); System.IO.File.WriteAllBytes(filepath, bytes); // Create the media database record GeneralMedia generalMedia = new GeneralMedia { Name = Path.GetFileNameWithoutExtension(uploadedName), MediaType = MediaType.FromString(fileType), FilePath = filepath, Size = new FileInfo(filepath).Length, }; await _Db.AddAsync(generalMedia); } else { return(new UnsupportedMediaTypeResult()); } await _Db.SaveChangesAsync(); return(Ok()); } catch (Exception ex) { _Logger.LogError("Error uploading file: {0}", ex.Message); _Logger.LogError(ex.StackTrace); return(BadRequest(new ResponseHelper("Something went wrong, please contact the devloper if the problem persists", ex.Message))); } }
/// <summary> /// Add audio media device to the application. /// </summary> /// <param name="audioMedia">The audio media device.</param> public void AddAudioCaptureDevice(AudioMedia audioMedia) { _endpoint.Endpoint.AddAudioCaptureDevice(audioMedia); }
/// <summary> /// Add audio media device to the application. /// </summary> /// <param name="audioMedia">The audio media device.</param> public void AddAudioPlaybackDevice(AudioMedia audioMedia) { _account.AddAudioPlaybackDevice(audioMedia); }
/// <summary> /// Add audio media device to the application. /// </summary> /// <param name="audioMedia">The audio media device.</param> public void AddAudioCaptureDevice(AudioMedia audioMedia) { _account.AddAudioCaptureDevice(audioMedia); }
public static AudioMediaPlayer typecastFromAudioMedia(AudioMedia media) { global::System.IntPtr cPtr = pjsua2PINVOKE.AudioMediaPlayer_typecastFromAudioMedia(AudioMedia.getCPtr(media)); AudioMediaPlayer ret = (cPtr == global::System.IntPtr.Zero) ? null : new AudioMediaPlayer(cPtr, false); return ret; }
public AudioMedia getCaptureDevMedia() { AudioMedia ret = new AudioMedia(pjsua2PINVOKE.AudDevManager_getCaptureDevMedia(swigCPtr), false); if (pjsua2PINVOKE.SWIGPendingException.Pending) throw pjsua2PINVOKE.SWIGPendingException.Retrieve(); return ret; }