Exemple #1
0
        async void InitializeAllJoyn()
        {
            Debug.UseOSLogging(true);
            Debug.SetDebugLevel("ALLJOYN", 7);

            _bus = new BusAttachment(APPLICATION_NAME, true, 4);
            string connectSpec = "null:";

            _bus.Start();

            try
            {
                _mp3Reader = new MP3Reader();

                if (_streamingSong != null)
                {
                    _streamingSongBasicProperties = await _streamingSong.GetBasicPropertiesAsync();

                    if (_streamingSongBasicProperties != null)
                    {
                        _streamingSongMusicProperties = await _streamingSong.Properties.GetMusicPropertiesAsync();

                        if (_streamingSongMusicProperties != null)
                        {
                            await _mp3Reader.SetFileAsync(_streamingSong);

                            _bus.ConnectAsync(connectSpec).AsTask().Wait();
                            _connected = true;

                            _listeners = new Listeners(_bus, this);
                            _bus.RegisterBusListener(_listeners);
                            _mediaSource = new MediaSource(_bus);
                            _audioStream = new AudioStream(_bus, "mp3", _mp3Reader, 100, 1000);
                            _mediaSource.AddStream(_audioStream);

                            /* Register MediaServer bus object */
                            _bus.RegisterBusObject(_mediaSource.MediaSourceBusObject);
                            /* Request a well known name */
                            _bus.RequestName(MediaServerName, (int)(RequestNameType.DBUS_NAME_REPLACE_EXISTING | RequestNameType.DBUS_NAME_DO_NOT_QUEUE));

                            /* Advertise name */
                            _bus.AdvertiseName(MediaServerName, TransportMaskType.TRANSPORT_ANY);

                            /* Bind a session for incoming client connections */
                            SessionOpts opts    = new SessionOpts(TrafficType.TRAFFIC_MESSAGES, true, ProximityType.PROXIMITY_ANY, TransportMaskType.TRANSPORT_ANY);
                            ushort[]    portOut = new ushort[1];
                            _bus.BindSessionPort(SESSION_PORT, portOut, opts, _listeners);
                        }
                    }
                }
            } catch (Exception ex)
            {
                string  message = ex.Message;
                QStatus status  = AllJoynException.GetErrorCode(ex.HResult);
                string  errMsg  = AllJoynException.GetErrorMessage(ex.HResult);
            }
        }
Exemple #2
0
        public AudioStream(BusAttachment bus, string name, MP3Reader mp3Reader, UInt32 jitter, UInt32 prefill)
        {
            _mediaStream = new MediaStream(bus, name, mp3Reader.GetDescription());
            _mediaPacer  = new MediaPacer(mp3Reader.GetDescription(), jitter, 0);
            _mp3Reader   = mp3Reader;
            _prefill     = prefill;

            _mediaStream.OnOpen         += OnOpen;
            _mediaStream.OnClose        += OnClose;
            _mediaStream.OnPlay         += OnPlay;
            _mediaStream.OnPause        += OnPause;
            _mediaStream.OnSeekRelative += OnSeekRelative;
            _mediaStream.OnSeekAbsolute += OnSeekAbsolute;

            _mediaPacer.JitterMiss    += JitterMiss;
            _mediaPacer.RequestFrames += RequestFrames;
            _buffer = new byte[_frameReadLength * _mp3Reader.FrameLen];
        }
        public AudioStream(BusAttachment bus, string name, MP3Reader mp3Reader, UInt32 jitter, UInt32 prefill)
        {
            _mediaStream = new MediaStream(bus, name, mp3Reader.GetDescription());
            _mediaPacer = new MediaPacer(mp3Reader.GetDescription(), jitter, 0);
            _mp3Reader = mp3Reader;
            _prefill = prefill;

            _mediaStream.OnOpen += OnOpen;
            _mediaStream.OnClose += OnClose;
            _mediaStream.OnPlay += OnPlay;
            _mediaStream.OnPause += OnPause;
            _mediaStream.OnSeekRelative += OnSeekRelative;
            _mediaStream.OnSeekAbsolute += OnSeekAbsolute;

            _mediaPacer.JitterMiss += JitterMiss;
            _mediaPacer.RequestFrames += RequestFrames;
            _buffer = new byte[_frameReadLength * _mp3Reader.FrameLen];

        }
        async void InitializeAllJoyn(){
            Debug.UseOSLogging(true);
            Debug.SetDebugLevel("ALLJOYN", 7);

            _bus = new BusAttachment(APPLICATION_NAME, true, 4);
            string connectSpec = "null:";
            _bus.Start();

            try
            {
                _mp3Reader = new MP3Reader();

                if (_streamingSong != null)
                {
                    _streamingSongBasicProperties = await _streamingSong.GetBasicPropertiesAsync();
                    if (_streamingSongBasicProperties != null)
                    {
                        _streamingSongMusicProperties = await _streamingSong.Properties.GetMusicPropertiesAsync();
                        if (_streamingSongMusicProperties != null)
                        {
                            await _mp3Reader.SetFileAsync(_streamingSong);

                            _bus.ConnectAsync(connectSpec).AsTask().Wait();
                            _connected = true;

                            _listeners = new Listeners(_bus, this);
                            _bus.RegisterBusListener(_listeners);
                            _mediaSource = new MediaSource(_bus);
                            _audioStream = new AudioStream(_bus, "mp3", _mp3Reader, 100, 1000);
                            _mediaSource.AddStream(_audioStream);

                            /* Register MediaServer bus object */ 
                            _bus.RegisterBusObject(_mediaSource.MediaSourceBusObject); 
                             /* Request a well known name */ 
                            _bus.RequestName(MediaServerName, (int)(RequestNameType.DBUS_NAME_REPLACE_EXISTING | RequestNameType.DBUS_NAME_DO_NOT_QUEUE));

                            /* Advertise name */
                            _bus.AdvertiseName(MediaServerName, TransportMaskType.TRANSPORT_ANY);
   
                            /* Bind a session for incoming client connections */
                            SessionOpts opts = new SessionOpts(TrafficType.TRAFFIC_MESSAGES, true, ProximityType.PROXIMITY_ANY, TransportMaskType.TRANSPORT_ANY);
                            ushort[] portOut = new ushort[1];
                            _bus.BindSessionPort(SESSION_PORT, portOut, opts, _listeners);
                        }
                    }
                }
            } catch (Exception ex)
            {
                string message = ex.Message;
                QStatus status = AllJoynException.GetErrorCode(ex.HResult);
                string errMsg = AllJoynException.GetErrorMessage(ex.HResult);
            }
        }