public override void onServiceConnected()
 {
     Log.d(TAG, "onServiceConnected");
     try
     {
         Sapa sapa = new Sapa();
         sapa.initialize(this);
         this.mSapaService      = new SapaService();
         this.mServiceConnected = true;
     }
     catch (SsdkUnsupportedException e)
     {
         Log.e(TAG, "Initialisation of Sapa is not possible as Sapa is not available on the device");
     }
     catch (InstantiationException e)
     {
         Log.e(TAG, "SapaService can not be instantiate");
     }
     if (this.mServiceConnected)
     {
         while (mDelayedIntents.Count > 0)
         {
             Intent intent = mDelayedIntents.RemoveFirst();
             if (intent != null)
             {
                 handleIntent(intent);
             }
         }
     }
 }
        public override void onServiceConnected()
        {
            Log.d(TAG, "onServiceConnected");
            try
            {
                if (this.mMyInfo == null)
                {
                    mMyInfo = mSapaAppService.getInstalledApp(this.PackageName);
                }
                if (mMyInfo != null)
                {
                    //Actions are being set in SapaAppInfo representing this application.
                    mActionArray = new SparseArray <SapaActionInfo>();
                    mActionArray.put(0, new SapaActionInfo(COMMAND_SHUSH, R.drawable.ctrl_btn_stop_default, PackageName));
                    mMyInfo.Actions = mActionArray;

                    //Native part is being initialised.
                    Sapa sapa = new Sapa();
                    sapa.initialize(this);
                    mSapaService   = new SapaService();
                    mSapaProcessor = new SapaProcessor(this, null, new SapaProcessorStateListener(this, mMyInfo.App));
                    mSapaService.register(mSapaProcessor);
                    mSapaProcessor.activate();

                    //Information about ports is being set in SapaAppInfo representing this app.
                    //It can not be done before activating SapaProcessor.
                    mMyInfo.PortFromSapaProcessor = mSapaProcessor;

                    //Application needs to declare that it was successfully activated.
                    if (mSapaAppService != null)
                    {
                        this.mSapaAppService.addActiveApp(this.mMyInfo);
                    }
                }
            }
            catch (SapaConnectionNotSetException e)
            {
                Log.e(TAG, "App could not be added to active as connection has not been made.");
            }
            catch (System.ArgumentException e)
            {
                Log.e(TAG, "Initialisation of Sapa is not possible due to invalid context of application");
            }
            catch (SsdkUnsupportedException e)
            {
                Log.e(TAG, "Initialisation of Sapa is not possible as Sapa is not available on the device");
            }
            catch (InstantiationException e)
            {
                Log.e(TAG, "SapaService can not be instantiate");
            }
        }
		public override void onCreate(Bundle savedInstanceState)
		{
			base.onCreate(savedInstanceState);
			ContentView = R.layout.activity_apasimple_client;

			try
			{
				Sapa sapa = new Sapa();
				sapa.initialize(this);
				mService = new SapaService();
				mService.stop(true);
				mService.start(SapaService.START_PARAM_DEFAULT_LATENCY);
				mClient = new SapaProcessor(this, null, new StatusListenerAnonymousInnerClassHelper(this));
				mService.register(mClient);

			}
			catch (SsdkUnsupportedException e)
			{
				Console.WriteLine(e.ToString());
				Console.Write(e.StackTrace);
				Toast.makeText(this, "not support professional audio", Toast.LENGTH_LONG).show();
				finish();
				return;
			}
			catch (InstantiationException e)
			{
				Console.WriteLine(e.ToString());
				Console.Write(e.StackTrace);
				Toast.makeText(this, "fail to instantiate", Toast.LENGTH_LONG).show();
				finish();
				return;
			}
			catch (AndroidRuntimeException e)
			{
				Console.WriteLine(e.ToString());
				Console.Write(e.StackTrace);
				Toast.makeText(this, "fail to start", Toast.LENGTH_LONG).show();
				finish();
				return;
			}

			mPlayButton = (Button) this.findViewById(R.id.play_button);
			mPlayButton.OnClickListener = new OnClickListenerAnonymousInnerClassHelper(this);

			mActivateButton = (Button) this.findViewById(R.id.button_activate);
			mActivateButton.OnClickListener = new OnClickListenerAnonymousInnerClassHelper2(this);

			mDeactivateButton = (Button) this.findViewById(R.id.button_deactivate);
			mDeactivateButton.OnClickListener = new OnClickListenerAnonymousInnerClassHelper3(this);
		}
Example #4
0
 /// <summary>
 /// This method is responsible for unregistering the processor of standalone instance, which
 /// means stopping it native part.
 /// </summary>
 private void stopSapaProcessor()
 {
     try
     {
         SapaService sapaService = new SapaService();
         sapaService.unregister(this.mProcessor);
     }
     catch (InstantiationException e)
     {
         // TODO Auto-generated catch block
         Console.WriteLine(e.ToString());
         Console.Write(e.StackTrace);
     }
 }
Example #5
0
        public override void onCreate(Bundle savedInstanceState)
        {
            base.onCreate(savedInstanceState);
            ContentView = R.layout.activity_apasimple_client;

            try
            {
                Sapa sapa = new Sapa();
                sapa.initialize(this);
                mService = new SapaService();
                mService.stop(true);
                mService.start(SapaService.START_PARAM_DEFAULT_LATENCY);
                mClient = new SapaProcessor(this, null, new StatusListenerAnonymousInnerClassHelper(this));
                mService.register(mClient);
            }
            catch (SsdkUnsupportedException e)
            {
                Console.WriteLine(e.ToString());
                Console.Write(e.StackTrace);
                Toast.makeText(this, "not support professional audio", Toast.LENGTH_LONG).show();
                finish();
                return;
            }
            catch (InstantiationException e)
            {
                Console.WriteLine(e.ToString());
                Console.Write(e.StackTrace);
                Toast.makeText(this, "fail to instantiate", Toast.LENGTH_LONG).show();
                finish();
                return;
            }
            catch (AndroidRuntimeException e)
            {
                Console.WriteLine(e.ToString());
                Console.Write(e.StackTrace);
                Toast.makeText(this, "fail to start", Toast.LENGTH_LONG).show();
                finish();
                return;
            }

            mPlayButton = (Button)this.findViewById(R.id.play_button);
            mPlayButton.OnClickListener = new OnClickListenerAnonymousInnerClassHelper(this);

            mActivateButton = (Button)this.findViewById(R.id.button_activate);
            mActivateButton.OnClickListener = new OnClickListenerAnonymousInnerClassHelper2(this);

            mDeactivateButton = (Button)this.findViewById(R.id.button_deactivate);
            mDeactivateButton.OnClickListener = new OnClickListenerAnonymousInnerClassHelper3(this);
        }
		protected internal override void onCreate(Bundle savedInstanceState)
		{
			base.onCreate(savedInstanceState);
			ContentView = R.layout.activity_sapa_simple_piano;

			try
			{
				(new Sapa()).initialize(this);
				mService = new SapaService();
				mService.start(SapaService.START_PARAM_DEFAULT_LATENCY);
				mProcessor = new SapaProcessor(this, null, new StatusListenerAnonymousInnerClassHelper(this));
				mService.register(mProcessor);

				// copy sound font file to sdcard.
				copyAssets();

				mProcessor.sendCommand("START");
				mProcessor.activate();

			}
			catch (SsdkUnsupportedException e)
			{
				Console.WriteLine(e.ToString());
				Console.Write(e.StackTrace);
				Toast.makeText(this, "Not support Professional Audio package", Toast.LENGTH_LONG).show();
				finish();
				return;
			}
			catch (System.ArgumentException e)
			{
				Console.WriteLine(e.ToString());
				Console.Write(e.StackTrace);
				Toast.makeText(this, "Error - invalid arguments. please check the log", Toast.LENGTH_LONG).show();
				finish();
				return;
			}
			catch (InstantiationException e)
			{
				Console.WriteLine(e.ToString());
				Console.Write(e.StackTrace);
				Toast.makeText(this, "Error. please check the log", Toast.LENGTH_LONG).show();
				finish();
				return;
			}

			((Button)findViewById(R.id.play_sound_c1)).OnClickListener = new OnClickListenerAnonymousInnerClassHelper(this);
		}
Example #7
0
        /// <summary>
        /// This method is responsible for connecting ports of standalone instance of application to
        /// system ports.
        /// </summary>
        /// <param name="sapaService"> </param>
        private void connectPorts(SapaService sapaService)
        {
            // Get lists of ports for connecting to system ports.
            IList <SapaPort> outPorts = new List <SapaPort>();
            IList <SapaPort> inPorts  = new List <SapaPort>();

            foreach (SapaPort port in mProcessor.Ports)
            {
                if (port.InOutType == SapaPort.INOUT_TYPE_OUT)
                {
                    outPorts.Add(port);
                }
                else
                {
                    inPorts.Add(port);
                }
            }

            // Create list of system ports to connect to.
            IList <SapaPort> systemInPorts  = new List <SapaPort>();
            IList <SapaPort> systemOutPorts = new List <SapaPort>();

            foreach (SapaPort port in sapaService.SystemPorts)
            {
                if (port.InOutType == SapaPort.INOUT_TYPE_IN && port.Name.contains("playback"))
                {
                    systemInPorts.Add(port);
                }
                else if (port.InOutType == SapaPort.INOUT_TYPE_OUT && port.Name.contains("capture"))
                {
                    systemOutPorts.Add(port);
                }
            }

            // Connect ports from two lists (first to first, second to second).
            if (outPorts.Count >= 2 && systemInPorts.Count >= 2)
            {
                sapaService.connect(new SapaPortConnection(outPorts[0], systemInPorts[0]));
                sapaService.connect(new SapaPortConnection(outPorts[1], systemInPorts[1]));
            }
            if (inPorts.Count >= 2 && systemOutPorts.Count >= 2)
            {
                sapaService.connect(new SapaPortConnection(systemOutPorts[0], inPorts[0]));
                sapaService.connect(new SapaPortConnection(systemOutPorts[1], inPorts[1]));
            }
        }
Example #8
0
        protected internal override void onCreate(Bundle savedInstanceState)
        {
            base.onCreate(savedInstanceState);
            ContentView = R.layout.activity_sapa_simple_piano;

            try
            {
                (new Sapa()).initialize(this);
                mService = new SapaService();
                mService.start(SapaService.START_PARAM_DEFAULT_LATENCY);
                mProcessor = new SapaProcessor(this, null, new StatusListenerAnonymousInnerClassHelper(this));
                mService.register(mProcessor);

                // copy sound font file to sdcard.
                copyAssets();

                mProcessor.sendCommand("START");
                mProcessor.activate();
            }
            catch (SsdkUnsupportedException e)
            {
                Console.WriteLine(e.ToString());
                Console.Write(e.StackTrace);
                Toast.makeText(this, "Not support Professional Audio package", Toast.LENGTH_LONG).show();
                finish();
                return;
            }
            catch (System.ArgumentException e)
            {
                Console.WriteLine(e.ToString());
                Console.Write(e.StackTrace);
                Toast.makeText(this, "Error - invalid arguments. please check the log", Toast.LENGTH_LONG).show();
                finish();
                return;
            }
            catch (InstantiationException e)
            {
                Console.WriteLine(e.ToString());
                Console.Write(e.StackTrace);
                Toast.makeText(this, "Error. please check the log", Toast.LENGTH_LONG).show();
                finish();
                return;
            }

            ((Button)findViewById(R.id.play_sound_c1)).OnClickListener = new OnClickListenerAnonymousInnerClassHelper(this);
        }
Example #9
0
        protected internal override void onDestroy()
        {
            Log.d(TAG, "onDestroy");
            // Native part is being stopped.
            this.stopSapaProcessor();
            SapaService sapaService;

            try
            {
                sapaService = new SapaService();
                sapaService.stop(false);
            }
            catch (InstantiationException)
            {
            }

            base.onDestroy();
        }
Example #10
0
        protected internal override void onDestroy()
        {
            Log.d(TAG, "onDestroy");
            // Native part is being stopped.
            this.stopSapaProcessor();
            SapaService sapaService;

            try
            {
                sapaService = new SapaService();
                // the force param should be false
                // to protect killing the SapaProcessors which is running with the Soundcamp.
                sapaService.stop(false);
            }
            catch (InstantiationException)
            {
            }
            base.onDestroy();
        }
Example #11
0
        /// <summary>
        /// This method is responsible for connecting ports of standalone instance of application to
        /// system ports.
        /// </summary>
        /// <param name="sapaService"> </param>
        private void connectPorts(SapaService sapaService)
        {
            // Get list of ports for connecting to system ports.
            IList <SapaPort> ports = new List <SapaPort>();

            foreach (SapaPort port in mProcessor.Ports)
            {
                if (port.InOutType == SapaPort.INOUT_TYPE_OUT)
                {
                    ports.Add(port);
                }
            }

            // Connect ports from two lists (first to first, second to second).
            if (ports.Count >= 2)
            {
                sapaService.connect(new SapaPortConnection(ports[0], sapaService.getSystemPort("playback_1")));
                sapaService.connect(new SapaPortConnection(ports[1], sapaService.getSystemPort("playback_2")));
            }
        }
Example #12
0
        /// <summary>
        /// This method is responsible for starting native part of the standalone instance of
        /// application. This means registering the processor, registering ports and connecting to system
        /// audio ports.
        /// </summary>
        private void startSapaProcessor()
        {
            try
            {
                (new Sapa()).initialize(this);
                SapaService sapaService = new SapaService();
                if (!sapaService.Started)
                {
                    sapaService.start(SapaService.START_PARAM_DEFAULT_LATENCY);
                }
                // Creating processor for stand alone version.
                this.mProcessor = new SapaProcessor(this, null, new StatusListenerAnonymousInnerClassHelper(this));
                // The processor is being registered.
                sapaService.register(this.mProcessor);

                // The processor is being activated.
                this.mProcessor.activate();

                // Audio output ports are being connected to system input ports.
                connectPorts(sapaService);
            }
            catch (InstantiationException e)
            {
                Log.w(TAG, "SapaService was not created");
                Console.WriteLine(e.ToString());
                Console.Write(e.StackTrace);
            }
            catch (System.ArgumentException e)
            {
                // TODO Auto-generated catch block
                Console.WriteLine(e.ToString());
                Console.Write(e.StackTrace);
            }
            catch (SsdkUnsupportedException e)
            {
                // TODO Auto-generated catch block
                Console.WriteLine(e.ToString());
                Console.Write(e.StackTrace);
            }
        }
		protected internal override void onCreate(Bundle savedInstanceState)
		{
			base.onCreate(savedInstanceState);
			ContentView = R.layout.activity_sapa_plugin_simple_client;

			try
			{
				Sapa sapa = new Sapa();
				sapa.initialize(this);
				mService = new SapaService();
				mService.start(SapaService.START_PARAM_DEFAULT_LATENCY);

			}
			catch (SsdkUnsupportedException e)
			{
				Toast.makeText(this, "Not support professional audio package", Toast.LENGTH_LONG).show();
				Console.WriteLine(e.ToString());
				Console.Write(e.StackTrace);
				finish();
				return;
			}
			catch (InstantiationException e)
			{
				Toast.makeText(this, "fail to instantiation SapaService", Toast.LENGTH_LONG).show();
				Console.WriteLine(e.ToString());
				Console.Write(e.StackTrace);
				finish();
				return;
			}

			((Button) findViewById(R.id.load_button)).Enabled = true;

			((Button) findViewById(R.id.load_button)).OnClickListener = new OnClickListenerAnonymousInnerClassHelper(this, e);

			((Button) findViewById(R.id.activate_button)).Enabled = false;
			((Button) findViewById(R.id.activate_button)).OnClickListener = new OnClickListenerAnonymousInnerClassHelper2(this);
		}
Example #14
0
        protected internal override void onCreate(Bundle savedInstanceState)
        {
            base.onCreate(savedInstanceState);
            ContentView = R.layout.activity_sapa_plugin_simple_client;

            try
            {
                Sapa sapa = new Sapa();
                sapa.initialize(this);
                mService = new SapaService();
                mService.start(SapaService.START_PARAM_DEFAULT_LATENCY);
            }
            catch (SsdkUnsupportedException e)
            {
                Toast.makeText(this, "Not support professional audio package", Toast.LENGTH_LONG).show();
                Console.WriteLine(e.ToString());
                Console.Write(e.StackTrace);
                finish();
                return;
            }
            catch (InstantiationException e)
            {
                Toast.makeText(this, "fail to instantiation SapaService", Toast.LENGTH_LONG).show();
                Console.WriteLine(e.ToString());
                Console.Write(e.StackTrace);
                finish();
                return;
            }

            ((Button)findViewById(R.id.load_button)).Enabled = true;

            ((Button)findViewById(R.id.load_button)).OnClickListener = new OnClickListenerAnonymousInnerClassHelper(this, e);

            ((Button)findViewById(R.id.activate_button)).Enabled         = false;
            ((Button)findViewById(R.id.activate_button)).OnClickListener = new OnClickListenerAnonymousInnerClassHelper2(this);
        }
        public override void onCreate(Bundle savedInstanceState)
        {
            base.onCreate(savedInstanceState);
            ContentView = R.layout.activity_main;

            List <string> availableList = new List <string>();

            try
            {
                Sapa sapa = new Sapa();
                sapa.initialize(this);
                mService = new SapaService();

                availableList.Add("Default");
                if (sapa.isFeatureEnabled(Sapa.SUPPORT_HIGH_LATENCY))
                {
                    availableList.Add("High");
                }
                if (sapa.isFeatureEnabled(Sapa.SUPPORT_MID_LATENCY))
                {
                    availableList.Add("Mid");
                }
                if (sapa.isFeatureEnabled(Sapa.SUPPORT_LOW_LATENCY))
                {
                    availableList.Add("Low");
                }
            }
            catch (SsdkUnsupportedException e1)
            {
                Console.WriteLine(e1.ToString());
                Console.Write(e1.StackTrace);
                Toast.makeText(this, "Not support Professional Audio package", Toast.LENGTH_LONG).show();
                finish();
                return;
            }
            catch (InstantiationException e)
            {
                Console.WriteLine(e.ToString());
                Console.Write(e.StackTrace);
                Toast.makeText(this, "Fail to create", Toast.LENGTH_LONG).show();
                finish();
                return;
            }

            mSyncStart = (Button)this.findViewById(R.id.sync_start);
            mSyncStart.OnClickListener = new OnClickListenerAnonymousInnerClassHelper(this);

            mSyncStop = (Button)this.findViewById(R.id.sync_stop);
            mSyncStop.OnClickListener = new OnClickListenerAnonymousInnerClassHelper2(this);

            mSetPosition = (Button)this.findViewById(R.id.set_position);
            mSetPosition.OnClickListener = new OnClickListenerAnonymousInnerClassHelper3(this);

            mButtonCon = (Button)findViewById(R.id.connect_button);
            mButtonCon.OnClickListener = new OnClickListenerAnonymousInnerClassHelper4(this, e);

            mButtonDisconnAll = (Button)findViewById(R.id.disconn_button);
            mButtonDisconnAll.OnClickListener = new OnClickListenerAnonymousInnerClassHelper5(this);

            mOnOffButton = (ToggleButton)findViewById(R.id.service_button);
            mOnOffButton.OnClickListener = new OnClickListenerAnonymousInnerClassHelper(this, e);

            mButtonAudio = (Button)findViewById(R.id.audio_tab_button);
            mButtonAudio.OnClickListener = new OnClickListenerAnonymousInnerClassHelper6(this);

            mButtonMidi = (Button)findViewById(R.id.midi_tab_button);
            mButtonMidi.OnClickListener = new OnClickListenerAnonymousInnerClassHelper7(this);

            mInputText  = (TextView)findViewById(R.id.inputport_text);
            mOutputText = (TextView)findViewById(R.id.outputport_text);

            mInputPortList = (ListView)findViewById(R.id.inputPort_listView);
            mInputPortList.OnItemClickListener = new OnItemClickListenerAnonymousInnerClassHelper(this);

            mOutputPortList = (ListView)findViewById(R.id.outputPort_listView);
            mOutputPortList.OnItemClickListener = new OnItemClickListenerAnonymousInnerClassHelper2(this);

            mConnected = (ListView)findViewById(R.id.connected_ListView);
            mConnected.OnItemClickListener = new OnItemClickListenerAnonymousInnerClassHelper3(this);

            mGetConn = (Button)findViewById(R.id.getconn_button);
            mGetConn.OnClickListener = new OnClickListenerAnonymousInnerClassHelper8(this);

            TextView tv = new TextView(ApplicationContext);

            tv.TextSize = 20;
            tv.Text     = "Input Port List";

            mInputPortList.addHeaderView(tv);

            TextView tv1 = new TextView(ApplicationContext);

            tv1.TextSize = 20;
            tv1.Text     = "OutPut Port List";

            mOutputPortList.addHeaderView(tv1);

            TextView tv2 = new TextView(ApplicationContext);

            tv2.TextSize = 20;
            tv2.Text     = "Connected Port List";

            mConnected.addHeaderView(tv2);

            mInputPortList.Adapter  = null;
            mOutputPortList.Adapter = null;
            mConnected.Adapter      = null;

            if (mService.Started == true)
            {
                mOnOffButton.Checked = true;
            }
            else
            {
                mOnOffButton.Checked = false;
            }



            spinner = (Spinner)findViewById(R.id.latency_spinner);
            string[] items = new string[availableList.Count];
            availableList.toArray(items);
            ArrayAdapter <string> spinnerArrayAdapter = new ArrayAdapter <string>(this, android.R.layout.simple_spinner_dropdown_item, items);

            spinner.OnItemSelectedListener = this;
            spinner.Adapter = spinnerArrayAdapter;
        }
		public override void onServiceConnected()
		{
			Log.d(TAG, "onServiceConnected");
			try
			{
				Sapa sapa = new Sapa();
				sapa.initialize(this);
				this.mSapaService = new SapaService();
				this.mServiceConnected = true;
			}
			catch (SsdkUnsupportedException e)
			{
				Log.e(TAG, "Initialisation of Sapa is not possible as Sapa is not available on the device");
			}
			catch (InstantiationException e)
			{
				Log.e(TAG, "SapaService can not be instantiate");
			}
			if (this.mServiceConnected)
			{
				while (mDelayedIntents.Count > 0)
				{
					Intent intent = mDelayedIntents.RemoveFirst();
					if (intent != null)
					{
						handleIntent(intent);
					}
				}
			}
		}
		/// <summary>
		/// This method is responsible for unregistering the processor of standalone instance, which
		/// means stopping it native part.
		/// </summary>
		private void stopSapaProcessor()
		{
			try
			{
				SapaService sapaService = new SapaService();
				sapaService.unregister(this.mProcessor);
			}
			catch (InstantiationException e)
			{
				// TODO Auto-generated catch block
				Console.WriteLine(e.ToString());
				Console.Write(e.StackTrace);
			}
		}
		protected internal override void onDestroy()
		{
			Log.d(TAG, "onDestroy");
			// Native part is being stopped.
			this.stopSapaProcessor();
			SapaService sapaService;
			try
			{
				sapaService = new SapaService();
				sapaService.stop(false);
			}
			catch (InstantiationException)
			{
			}

			base.onDestroy();
		}
		/// <summary>
		/// This method is responsible for connecting ports of standalone instance of application to
		/// system ports.
		/// </summary>
		/// <param name="sapaService"> </param>
		private void connectPorts(SapaService sapaService)
		{

			// Get lists of ports for connecting to system ports.
			IList<SapaPort> outPorts = new List<SapaPort>();
			IList<SapaPort> inPorts = new List<SapaPort>();
			foreach (SapaPort port in mProcessor.Ports)
			{
				if (port.InOutType == SapaPort.INOUT_TYPE_OUT)
				{
					outPorts.Add(port);
				}
				else
				{
					inPorts.Add(port);
				}
			}

			// Create list of system ports to connect to.
			IList<SapaPort> systemInPorts = new List<SapaPort>();
			IList<SapaPort> systemOutPorts = new List<SapaPort>();
			foreach (SapaPort port in sapaService.SystemPorts)
			{
				if (port.InOutType == SapaPort.INOUT_TYPE_IN && port.Name.contains("playback"))
				{
					systemInPorts.Add(port);
				}
				else if (port.InOutType == SapaPort.INOUT_TYPE_OUT && port.Name.contains("capture"))
				{
					systemOutPorts.Add(port);
				}
			}

			// Connect ports from two lists (first to first, second to second).
			if (outPorts.Count >= 2 && systemInPorts.Count >= 2)
			{
				sapaService.connect(new SapaPortConnection(outPorts[0], systemInPorts[0]));
				sapaService.connect(new SapaPortConnection(outPorts[1], systemInPorts[1]));
			}
			if (inPorts.Count >= 2 && systemOutPorts.Count >= 2)
			{
				sapaService.connect(new SapaPortConnection(systemOutPorts[0], inPorts[0]));
				sapaService.connect(new SapaPortConnection(systemOutPorts[1], inPorts[1]));
			}
		}
		/// <summary>
		/// This method is responsible for starting native part of the standalone instance of
		/// application. This means registering the processor, registering ports and connecting to system
		/// audio ports.
		/// </summary>
		private void startSapaProcessor()
		{
			try
			{
				(new Sapa()).initialize(this);
				SapaService sapaService = new SapaService();
				if (!sapaService.Started)
				{
					sapaService.start(SapaService.START_PARAM_DEFAULT_LATENCY);
				}
				// Creating processor for stand alone version.
				this.mProcessor = new SapaProcessor(this, null, new StatusListenerAnonymousInnerClassHelper(this));
				// The processor is being registered.
				sapaService.register(this.mProcessor);

				// The processor is being activated.
				this.mProcessor.activate();

				// Audio output ports are being connected to system input ports.
				connectPorts(sapaService);

			}
			catch (InstantiationException e)
			{
				Log.w(TAG, "SapaService was not created");
				Console.WriteLine(e.ToString());
				Console.Write(e.StackTrace);
			}
			catch (System.ArgumentException e)
			{
				// TODO Auto-generated catch block
				Console.WriteLine(e.ToString());
				Console.Write(e.StackTrace);
			}
			catch (SsdkUnsupportedException e)
			{
				// TODO Auto-generated catch block
				Console.WriteLine(e.ToString());
				Console.Write(e.StackTrace);
			}
		}
		protected internal override void onDestroy()
		{
			Log.d(TAG, "onDestroy");
			// Native part is being stopped.
			this.stopSapaProcessor();
			SapaService sapaService;
			try
			{
				sapaService = new SapaService();
				// the force param should be false 
				// to protect killing the SapaProcessors which is running with the Soundcamp.
				sapaService.stop(false);
			}
			catch (InstantiationException)
			{
			}
			base.onDestroy();
		}
		/// <summary>
		/// This method is responsible for connecting ports of standalone instance of application to
		/// system ports.
		/// </summary>
		/// <param name="sapaService"> </param>
		private void connectPorts(SapaService sapaService)
		{

			// Get list of ports for connecting to system ports.
			IList<SapaPort> ports = new List<SapaPort>();
			foreach (SapaPort port in mProcessor.Ports)
			{
				if (port.InOutType == SapaPort.INOUT_TYPE_OUT)
				{
					ports.Add(port);
				}
			}

			// Connect ports from two lists (first to first, second to second).
			if (ports.Count >= 2)
			{
				sapaService.connect(new SapaPortConnection(ports[0], sapaService.getSystemPort("playback_1")));
				sapaService.connect(new SapaPortConnection(ports[1], sapaService.getSystemPort("playback_2")));
			}
		}
		public override void onServiceConnected()
		{
			Log.d(TAG, "onServiceConnected");
			try
			{
				if (this.mMyInfo == null)
				{
					mMyInfo = mSapaAppService.getInstalledApp(this.PackageName);
				}
				if (mMyInfo != null)
				{

					//Actions are being set in SapaAppInfo representing this application.
					mActionArray = new SparseArray<SapaActionInfo>();
					mActionArray.put(0, new SapaActionInfo(COMMAND_SHUSH, R.drawable.ctrl_btn_stop_default, PackageName));
					mMyInfo.Actions = mActionArray;

					//Native part is being initialised.
					Sapa sapa = new Sapa();
					sapa.initialize(this);
					mSapaService = new SapaService();
					mSapaProcessor = new SapaProcessor(this, null, new SapaProcessorStateListener(this, mMyInfo.App));
					mSapaService.register(mSapaProcessor);
					mSapaProcessor.activate();

					//Information about ports is being set in SapaAppInfo representing this app.
					//It can not be done before activating SapaProcessor.
					mMyInfo.PortFromSapaProcessor = mSapaProcessor;

					//Application needs to declare that it was successfully activated.
					if (mSapaAppService != null)
					{
						this.mSapaAppService.addActiveApp(this.mMyInfo);
					}
				}
			}
			catch (SapaConnectionNotSetException e)
			{
				Log.e(TAG, "App could not be added to active as connection has not been made.");
			}
			catch (System.ArgumentException e)
			{
				Log.e(TAG, "Initialisation of Sapa is not possible due to invalid context of application");
			}
			catch (SsdkUnsupportedException e)
			{
				Log.e(TAG, "Initialisation of Sapa is not possible as Sapa is not available on the device");
			}
			catch (InstantiationException e)
			{
				Log.e(TAG, "SapaService can not be instantiate");
			}
		}