In Reading mode, will close the underlying ogg file and free its resources. In Writing mode, will write out the Info and Tags objects, and then the audio data.
()
| 191 | * Tags objects, and then the audio data. |
| 192 | */ |
| 193 | public void close() throws IOException { |
| 194 | if(r != null) { |
| 195 | r = null; |
| 196 | ogg.close(); |
| 197 | ogg = null; |
| 198 | } |
| 199 | if(w != null) { |
| 200 | w.bufferPacket(info.write(), true); |
| 201 | w.bufferPacket(tags.write(), false); |
| 202 | |
| 203 | long lastGranule = 0; |
| 204 | for(OpusAudioData vd : writtenPackets) { |
| 205 | // Update the granule position as we go |
| 206 | if(vd.getGranulePosition() >= 0 && |
| 207 | lastGranule != vd.getGranulePosition()) { |
| 208 | w.flush(); |
| 209 | lastGranule = vd.getGranulePosition(); |
| 210 | w.setGranulePosition(lastGranule); |
| 211 | } |
| 212 | |
| 213 | // Write the data, flushing if needed |
| 214 | w.bufferPacket(vd.write()); |
| 215 | if(w.getSizePendingFlush() > 16384) { |
| 216 | w.flush(); |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | w.close(); |
| 221 | w = null; |
| 222 | ogg.close(); |
| 223 | ogg = null; |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | /** |
| 228 | * Returns the underlying Ogg File instance |