@@ -123,15 +123,15 @@ class A2DPStream : public AudioStream, public VolumeSupport {
123
123
}
124
124
125
125
// / Starts the processing
126
- bool begin (RxTxMode mode, const char * name){
126
+ bool begin (RxTxMode mode, const char * name, bool wait_for_connection= true ){
127
127
A2DPConfig cfg;
128
128
cfg.mode = mode;
129
129
cfg.name = name;
130
- return begin (cfg);
130
+ return begin (cfg, wait_for_connection );
131
131
}
132
132
133
133
// / Starts the processing
134
- bool begin (A2DPConfig cfg){
134
+ bool begin (A2DPConfig cfg, bool wait_for_connection= true ){
135
135
this ->config = cfg;
136
136
bool result = false ;
137
137
LOGI (" Connecting to %s" ,cfg.name );
@@ -158,14 +158,19 @@ class A2DPStream : public AudioStream, public VolumeSupport {
158
158
a2dp_source->set_ssid_callback (detected_device);
159
159
}
160
160
a2dp_source->set_on_connection_state_changed (a2dp_state_callback, this );
161
- a2dp_source->start_raw ((char *)cfg.name , a2dp_stream_source_sound_data);
162
- while (!a2dp_source->is_connected ()){
163
- LOGD (" waiting for connection" );
164
- delay (1000 );
161
+ a2dp_source->start_raw ((char *)cfg.name , a2dp_stream_source_sound_data);
162
+ if (wait_for_connection){
163
+ while (!a2dp_source->is_connected ()){
164
+ LOGD (" waiting for connection" );
165
+ delay (1000 );
166
+ }
167
+ LOGI (" a2dp_source is connected..." );
168
+ notify_base_Info (44100 );
169
+ // is_a2dp_active = true;
170
+ }
171
+ else {
172
+ LOGI (" a2dp_source started without connecting" );
165
173
}
166
- LOGI (" a2dp_source is connected..." );
167
- notify_base_Info (44100 );
168
- // is_a2dp_active = true;
169
174
result = true ;
170
175
break ;
171
176
@@ -178,11 +183,16 @@ class A2DPStream : public AudioStream, public VolumeSupport {
178
183
a2dp_sink->set_on_connection_state_changed (a2dp_state_callback, this );
179
184
a2dp_sink->set_sample_rate_callback (sample_rate_callback);
180
185
a2dp_sink->start ((char *)cfg.name );
181
- while (!a2dp_sink->is_connected ()){
182
- LOGD (" waiting for connection" );
183
- delay (1000 );
186
+ if (wait_for_connection){
187
+ while (!a2dp_sink->is_connected ()){
188
+ LOGD (" waiting for connection" );
189
+ delay (1000 );
190
+ }
191
+ LOGI (" a2dp_sink is connected..." );
192
+ }
193
+ else {
194
+ LOGI (" a2dp_sink started without connection" );
184
195
}
185
- LOGI (" a2dp_sink is connected..." );
186
196
is_a2dp_active = true ;
187
197
result = true ;
188
198
break ;
0 commit comments