Android Wear: ChannelIOException: Channel closed unexpectedly before stream was finished
Asked Answered
I

0

6

I am using Channel to send audio data to handheld from the wear. However, when I wrote data into the channelstream, the program sometimes was stuck at the code where I write data into the stream and threw out an exception:

com.google.android.gms.wearable.ChannelIOException: Channel closed unexpectedly before stream was finished .

I did not find much similar questions as mine. Does anyone have some ideas on how to fix it? Thanks a lot for your time!

The code I am using to write data into channel is:

// OS is the output stream to write the data into the local file system on the android wear device.
    if(null != os){
                    while(isWriting){
                        read = audioRecord.read(data, 0, recBufSize);
                        if(AudioRecord.ERROR_INVALID_OPERATION != read){
                            try {
                                if(sChannelOutputStream!=null) {
                                    Log.d(Constants.TAG,"Schanneloutput write starts+ readsize:"+read);
                                    sChannelOutputStream.write(data);
                                    Log.d(Constants.TAG, "Schanneloutput write ends");
                                }
                                os.write(data);
                            } catch (IOException e) {
                                e.printStackTrace();
                            }
                        }
                    }

                    try {
                        os.close();
                        if(sChannelOutputStream!=null){
                            Log.d(Constants.TAG,"Schannel out close");
                            sChannelOutputStream.close();
                            sChannelOutputStream = null;
                        }

                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
Invade answered 13/9, 2015 at 0:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.