示例#1
0
    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);
    }
示例#2
0
        /// <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;
                }
            }
        }
示例#3
0
 /// <summary>
 /// Stop the sound file and cleanup.
 /// </summary>
 public void StopSoundFile()
 {
     if (_player != null)
     {
         try
         {
             _player.Dispose();
         }
         catch { }
     }
     _player = null;
 }
示例#4
0
        /// <summary>
        /// On player end of file.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void _player_OnPlayerEndOfFile(object sender, bool e)
        {
            if (_player != null)
            {
                try
                {
                    // Call end of file.
                    OnPlayerEndOfFile?.Invoke(this, new EventArgs());

                    // Close the player.
                    _player.Dispose();
                }
                catch { }
                _player = null;
            }
        }
示例#5
0
        /// <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 { }
                }
            }
        }
示例#6
0
        /// <summary>
        /// Dispose(bool disposing) executes in two distinct scenarios.
        /// If disposing equals true, the method has been called directly
        /// or indirectly by a user's code. Managed and unmanaged resources
        /// can be disposed.
        /// If disposing equals false, the method has been called by the
        /// runtime from inside the finalizer and you should not reference
        /// other objects. Only unmanaged resources can be disposed.
        /// </summary>
        protected virtual void Dispose(bool disposing)
        {
            // Check to see if Dispose has already been called.
            if (!this._disposed)
            {
                // Note disposing has been done.
                _disposed = true;

                // If disposing equals true, dispose all managed
                // and unmanaged resources.
                if (disposing)
                {
                    // If current call.
                    if (_call != null)
                    {
                        try
                        {
                            // Cleanup the call.
                            _call.Dispose();
                        }
                        catch { }
                    }

                    // If recoder.
                    if (_recorder != null)
                    {
                        try
                        {
                            // Cleanup the recoder.
                            _recorder.Dispose();
                        }
                        catch { }
                    }

                    // If auto answer recoder.
                    if (_recorderAutoAnswer != null)
                    {
                        try
                        {
                            // Cleanup the recoder.
                            _recorderAutoAnswer.Dispose();
                        }
                        catch { }
                    }

                    // If sound player.
                    if (_player != null)
                    {
                        try
                        {
                            // Cleanup the recoder.
                            _player.Dispose();
                        }
                        catch { }
                    }

                    // If video window.
                    if (_videoWindow != null)
                    {
                        try
                        {
                            // Cleanup the video window.
                            _videoWindow.Dispose();
                        }
                        catch { }
                    }

                    // Cleanup the audio media.
                    if (_audioMedias != null)
                    {
                        _audioMedias.Clear();
                    }
                }

                // Call the appropriate methods to clean up
                // unmanaged resources here.
                _player             = null;
                _recorder           = null;
                _recorderAutoAnswer = null;
                _videoWindow        = null;
                _audioMedias        = null;
            }
        }
示例#7
0
 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(AudioMediaPlayer obj)
 {
     return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
 }
示例#8
0
 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(AudioMediaPlayer obj)
 {
     return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr);
 }