| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
package org.jaudiotagger.audio.mp3; |
| 21 | |
|
| 22 | |
import org.jaudiotagger.audio.AudioHeader; |
| 23 | |
import org.jaudiotagger.audio.exceptions.InvalidAudioFrameException; |
| 24 | |
import org.jaudiotagger.logging.Hex; |
| 25 | |
|
| 26 | |
import java.io.EOFException; |
| 27 | |
import java.io.File; |
| 28 | |
import java.io.FileInputStream; |
| 29 | |
import java.io.IOException; |
| 30 | |
import java.nio.ByteBuffer; |
| 31 | |
import java.nio.channels.FileChannel; |
| 32 | |
import java.text.ParseException; |
| 33 | |
import java.text.SimpleDateFormat; |
| 34 | |
import java.util.Date; |
| 35 | |
import java.util.Locale; |
| 36 | |
import java.util.logging.Level; |
| 37 | |
import java.util.logging.Logger; |
| 38 | |
|
| 39 | |
|
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | |
|
| 52 | |
|
| 53 | |
|
| 54 | |
|
| 55 | |
|
| 56 | |
|
| 57 | |
|
| 58 | |
|
| 59 | |
|
| 60 | |
public class MP3AudioHeader implements AudioHeader |
| 61 | |
{ |
| 62 | |
protected MPEGFrameHeader mp3FrameHeader; |
| 63 | |
protected XingFrame mp3XingFrame; |
| 64 | |
protected VbriFrame mp3VbriFrame; |
| 65 | |
|
| 66 | |
|
| 67 | |
private long fileSize; |
| 68 | |
private long startByte; |
| 69 | |
private double timePerFrame; |
| 70 | |
private double trackLength; |
| 71 | |
private long numberOfFrames; |
| 72 | |
private long numberOfFramesEstimate; |
| 73 | |
private long bitrate; |
| 74 | 2105 | private String encoder = ""; |
| 75 | |
|
| 76 | 4 | private static final SimpleDateFormat timeInFormat = new SimpleDateFormat("ss", Locale.UK); |
| 77 | 4 | private static final SimpleDateFormat timeOutFormat = new SimpleDateFormat("mm:ss",Locale.UK); |
| 78 | 4 | private static final SimpleDateFormat timeOutOverAnHourFormat = new SimpleDateFormat("kk:mm:ss",Locale.UK); |
| 79 | |
private static final char isVbrIdentifier = '~'; |
| 80 | |
private static final int CONVERT_TO_KILOBITS = 1000; |
| 81 | |
private static final String TYPE_MP3 = "mp3"; |
| 82 | |
private static final int CONVERTS_BYTE_TO_BITS = 8; |
| 83 | |
|
| 84 | |
|
| 85 | 4 | public static Logger logger = Logger.getLogger("org.jaudiotagger.audio.mp3"); |
| 86 | |
|
| 87 | |
|
| 88 | |
|
| 89 | |
|
| 90 | |
|
| 91 | |
private final static int FILE_BUFFER_SIZE = 5000; |
| 92 | |
private final static int MIN_BUFFER_REMAINING_REQUIRED = MPEGFrameHeader.HEADER_SIZE + XingFrame.MAX_BUFFER_SIZE_NEEDED_TO_READ_XING; |
| 93 | |
private static final int NO_SECONDS_IN_HOUR = 3600; |
| 94 | |
|
| 95 | |
public MP3AudioHeader() |
| 96 | 0 | { |
| 97 | 0 | } |
| 98 | |
|
| 99 | |
|
| 100 | |
|
| 101 | |
|
| 102 | |
|
| 103 | |
|
| 104 | |
|
| 105 | |
|
| 106 | |
|
| 107 | |
|
| 108 | |
|
| 109 | |
public MP3AudioHeader(final File seekFile) throws IOException, InvalidAudioFrameException |
| 110 | 0 | { |
| 111 | 0 | if (!seek(seekFile, 0)) |
| 112 | |
{ |
| 113 | 0 | throw new InvalidAudioFrameException("No audio header found within" + seekFile.getName()); |
| 114 | |
} |
| 115 | 0 | } |
| 116 | |
|
| 117 | |
|
| 118 | |
|
| 119 | |
|
| 120 | |
|
| 121 | |
|
| 122 | |
|
| 123 | |
|
| 124 | |
|
| 125 | |
|
| 126 | |
|
| 127 | |
|
| 128 | |
|
| 129 | |
|
| 130 | |
|
| 131 | |
|
| 132 | |
|
| 133 | |
|
| 134 | |
public MP3AudioHeader(final File seekFile, long startByte) throws IOException, InvalidAudioFrameException |
| 135 | 2105 | { |
| 136 | 2105 | if (!seek(seekFile, startByte)) |
| 137 | |
{ |
| 138 | 12 | throw new InvalidAudioFrameException("No audio header found within" + seekFile.getName()); |
| 139 | |
} |
| 140 | 2093 | } |
| 141 | |
|
| 142 | |
|
| 143 | |
|
| 144 | |
|
| 145 | |
|
| 146 | |
|
| 147 | |
|
| 148 | |
|
| 149 | |
|
| 150 | |
|
| 151 | |
|
| 152 | |
|
| 153 | |
public boolean seek(final File seekFile, long startByte) throws IOException |
| 154 | |
{ |
| 155 | |
|
| 156 | |
|
| 157 | |
long filePointerCount; |
| 158 | |
|
| 159 | 2105 | final FileInputStream fis = new FileInputStream(seekFile); |
| 160 | 2105 | final FileChannel fc = fis.getChannel(); |
| 161 | |
|
| 162 | |
|
| 163 | 2105 | ByteBuffer bb = ByteBuffer.allocateDirect(FILE_BUFFER_SIZE); |
| 164 | |
|
| 165 | |
|
| 166 | 2105 | fc.position(startByte); |
| 167 | |
|
| 168 | |
|
| 169 | 2105 | filePointerCount = startByte; |
| 170 | |
|
| 171 | |
|
| 172 | 2105 | fc.read(bb, startByte); |
| 173 | 2105 | bb.flip(); |
| 174 | |
|
| 175 | 2105 | boolean syncFound = false; |
| 176 | |
try |
| 177 | |
{ |
| 178 | |
do |
| 179 | |
{ |
| 180 | |
|
| 181 | |
|
| 182 | |
|
| 183 | 309717 | if (bb.remaining() <= MIN_BUFFER_REMAINING_REQUIRED) |
| 184 | |
{ |
| 185 | 50 | bb.clear(); |
| 186 | 50 | fc.position(filePointerCount); |
| 187 | 50 | fc.read(bb, fc.position()); |
| 188 | 50 | bb.flip(); |
| 189 | 50 | if (bb.limit() <= MIN_BUFFER_REMAINING_REQUIRED) |
| 190 | |
{ |
| 191 | |
|
| 192 | 12 | return false; |
| 193 | |
} |
| 194 | |
} |
| 195 | |
|
| 196 | 309705 | if (MPEGFrameHeader.isMPEGFrame(bb)) |
| 197 | |
{ |
| 198 | |
try |
| 199 | |
{ |
| 200 | 2415 | if (MP3AudioHeader.logger.isLoggable(Level.FINEST)) |
| 201 | |
{ |
| 202 | 1180 | MP3AudioHeader.logger.finest("Found Possible header at:" + filePointerCount); |
| 203 | |
} |
| 204 | |
|
| 205 | 2415 | mp3FrameHeader = MPEGFrameHeader.parseMPEGHeader(bb); |
| 206 | 2202 | syncFound = true; |
| 207 | |
|
| 208 | 2202 | if (XingFrame.isXingFrame(bb, mp3FrameHeader)) |
| 209 | |
{ |
| 210 | 2023 | if (MP3AudioHeader.logger.isLoggable(Level.FINEST)) |
| 211 | |
{ |
| 212 | 1008 | MP3AudioHeader.logger.finest("Found Possible XingHeader"); |
| 213 | |
} |
| 214 | |
try |
| 215 | |
{ |
| 216 | |
|
| 217 | 2023 | mp3XingFrame = XingFrame.parseXingFrame(); |
| 218 | |
} |
| 219 | 0 | catch (InvalidAudioFrameException ex) |
| 220 | |
{ |
| 221 | |
|
| 222 | |
|
| 223 | 2023 | } |
| 224 | 2023 | break; |
| 225 | |
} |
| 226 | 179 | else if (VbriFrame.isVbriFrame(bb, mp3FrameHeader)) |
| 227 | |
{ |
| 228 | 4 | if (MP3AudioHeader.logger.isLoggable(Level.FINEST)) |
| 229 | |
{ |
| 230 | 0 | MP3AudioHeader.logger.finest("Found Possible VbriHeader"); |
| 231 | |
} |
| 232 | |
try |
| 233 | |
{ |
| 234 | |
|
| 235 | 4 | mp3VbriFrame = VbriFrame.parseVBRIFrame(); |
| 236 | |
} |
| 237 | 0 | catch (InvalidAudioFrameException ex) |
| 238 | |
{ |
| 239 | |
|
| 240 | |
|
| 241 | 4 | } |
| 242 | 4 | break; |
| 243 | |
} |
| 244 | |
|
| 245 | |
|
| 246 | |
|
| 247 | |
|
| 248 | |
|
| 249 | |
|
| 250 | |
|
| 251 | |
|
| 252 | |
else |
| 253 | |
{ |
| 254 | 175 | syncFound = isNextFrameValid(seekFile, filePointerCount, bb, fc); |
| 255 | 175 | if (syncFound) |
| 256 | |
{ |
| 257 | 66 | break; |
| 258 | |
} |
| 259 | |
} |
| 260 | |
|
| 261 | |
} |
| 262 | 213 | catch (InvalidAudioFrameException ex) |
| 263 | |
{ |
| 264 | |
|
| 265 | |
|
| 266 | 109 | } |
| 267 | |
} |
| 268 | |
|
| 269 | |
|
| 270 | |
|
| 271 | 307612 | bb.position(bb.position() + 1); |
| 272 | 307612 | filePointerCount++; |
| 273 | |
|
| 274 | |
|
| 275 | |
} |
| 276 | 307612 | while (!syncFound); |
| 277 | 2093 | } |
| 278 | 0 | catch (EOFException ex) |
| 279 | |
{ |
| 280 | 0 | MP3AudioHeader.logger.log(Level.WARNING, "Reached end of file without finding sync match", ex); |
| 281 | 0 | syncFound = false; |
| 282 | 0 | } |
| 283 | 0 | catch (IOException iox) |
| 284 | |
{ |
| 285 | 0 | MP3AudioHeader.logger.log(Level.SEVERE, "IOException occurred whilst trying to find sync", iox); |
| 286 | 0 | syncFound = false; |
| 287 | 0 | throw iox; |
| 288 | |
} |
| 289 | |
finally |
| 290 | |
{ |
| 291 | 0 | if (fc != null) |
| 292 | |
{ |
| 293 | 2105 | fc.close(); |
| 294 | |
} |
| 295 | |
|
| 296 | 2105 | if (fis != null) |
| 297 | |
{ |
| 298 | 2105 | fis.close(); |
| 299 | |
} |
| 300 | 2093 | } |
| 301 | |
|
| 302 | |
|
| 303 | 2093 | if (MP3AudioHeader.logger.isLoggable(Level.FINEST)) |
| 304 | |
{ |
| 305 | 1034 | MP3AudioHeader.logger.finer("Return found matching mp3 header starting at" + filePointerCount); |
| 306 | |
} |
| 307 | 2093 | setFileSize(seekFile.length()); |
| 308 | 2093 | setMp3StartByte(filePointerCount); |
| 309 | 2093 | setTimePerFrame(); |
| 310 | 2093 | setNumberOfFrames(); |
| 311 | 2093 | setTrackLength(); |
| 312 | 2093 | setBitRate(); |
| 313 | 2093 | setEncoder(); |
| 314 | |
|
| 315 | |
|
| 316 | |
|
| 317 | |
|
| 318 | |
|
| 319 | 2093 | return syncFound; |
| 320 | |
} |
| 321 | |
|
| 322 | |
|
| 323 | |
|
| 324 | |
|
| 325 | |
|
| 326 | |
|
| 327 | |
|
| 328 | |
|
| 329 | |
|
| 330 | |
|
| 331 | |
|
| 332 | |
private boolean isNextFrameValid(File seekFile, long filePointerCount, ByteBuffer bb, FileChannel fc) throws IOException |
| 333 | |
{ |
| 334 | 175 | if (MP3AudioHeader.logger.isLoggable(Level.FINEST)) |
| 335 | |
{ |
| 336 | 70 | MP3AudioHeader.logger.finer("Checking next frame" + seekFile.getName() + ":fpc:" + filePointerCount + "skipping to:" + (filePointerCount + mp3FrameHeader.getFrameLength())); |
| 337 | |
} |
| 338 | 175 | boolean result = false; |
| 339 | |
|
| 340 | 175 | int currentPosition = bb.position(); |
| 341 | |
|
| 342 | |
|
| 343 | |
|
| 344 | |
|
| 345 | 175 | if (mp3FrameHeader.getFrameLength() > (FILE_BUFFER_SIZE - MIN_BUFFER_REMAINING_REQUIRED)) |
| 346 | |
{ |
| 347 | 0 | MP3AudioHeader.logger.finer("Frame size is too large to be a frame:" + mp3FrameHeader.getFrameLength()); |
| 348 | 0 | return false; |
| 349 | |
} |
| 350 | |
|
| 351 | |
|
| 352 | 175 | if (bb.remaining() <= MIN_BUFFER_REMAINING_REQUIRED + mp3FrameHeader.getFrameLength()) |
| 353 | |
{ |
| 354 | 8 | MP3AudioHeader.logger.finer("Buffer too small, need to reload, buffer size:" + bb.remaining()); |
| 355 | 8 | bb.clear(); |
| 356 | 8 | fc.position(filePointerCount); |
| 357 | 8 | fc.read(bb, fc.position()); |
| 358 | 8 | bb.flip(); |
| 359 | |
|
| 360 | 8 | currentPosition = 0; |
| 361 | |
|
| 362 | 8 | if (bb.limit() <= MIN_BUFFER_REMAINING_REQUIRED) |
| 363 | |
{ |
| 364 | |
|
| 365 | 0 | MP3AudioHeader.logger.finer("Nearly at end of file, no header found:"); |
| 366 | 0 | return false; |
| 367 | |
} |
| 368 | |
|
| 369 | |
|
| 370 | 8 | if (bb.limit() <= MIN_BUFFER_REMAINING_REQUIRED + mp3FrameHeader.getFrameLength()) |
| 371 | |
{ |
| 372 | |
|
| 373 | 8 | MP3AudioHeader.logger.finer("Nearly at end of file, no room for next frame, no header found:"); |
| 374 | 8 | return false; |
| 375 | |
} |
| 376 | |
} |
| 377 | |
|
| 378 | |
|
| 379 | 167 | bb.position(bb.position() + mp3FrameHeader.getFrameLength()); |
| 380 | 167 | if (MPEGFrameHeader.isMPEGFrame(bb)) |
| 381 | |
{ |
| 382 | |
try |
| 383 | |
{ |
| 384 | 66 | MPEGFrameHeader.parseMPEGHeader(bb); |
| 385 | 66 | MP3AudioHeader.logger.finer("Check next frame confirms is an audio header "); |
| 386 | 66 | result = true; |
| 387 | |
} |
| 388 | 0 | catch (InvalidAudioFrameException ex) |
| 389 | |
{ |
| 390 | 0 | MP3AudioHeader.logger.finer("Check next frame has identified this is not an audio header"); |
| 391 | 0 | result = false; |
| 392 | 66 | } |
| 393 | |
} |
| 394 | |
else |
| 395 | |
{ |
| 396 | 101 | MP3AudioHeader.logger.finer("isMPEGFrame has identified this is not an audio header"); |
| 397 | |
} |
| 398 | |
|
| 399 | 167 | bb.position(currentPosition); |
| 400 | 167 | return result; |
| 401 | |
} |
| 402 | |
|
| 403 | |
|
| 404 | |
|
| 405 | |
|
| 406 | |
|
| 407 | |
|
| 408 | |
protected void setMp3StartByte(final long startByte) |
| 409 | |
{ |
| 410 | 2093 | this.startByte = startByte; |
| 411 | 2093 | } |
| 412 | |
|
| 413 | |
|
| 414 | |
|
| 415 | |
|
| 416 | |
|
| 417 | |
|
| 418 | |
|
| 419 | |
|
| 420 | |
|
| 421 | |
public long getMp3StartByte() |
| 422 | |
{ |
| 423 | 5532 | return startByte; |
| 424 | |
} |
| 425 | |
|
| 426 | |
|
| 427 | |
|
| 428 | |
|
| 429 | |
|
| 430 | |
protected void setNumberOfFrames() |
| 431 | |
{ |
| 432 | 2093 | numberOfFramesEstimate = (fileSize - startByte) / mp3FrameHeader.getFrameLength(); |
| 433 | |
|
| 434 | 2093 | if (mp3XingFrame != null && mp3XingFrame.isFrameCountEnabled()) |
| 435 | |
{ |
| 436 | 2023 | numberOfFrames = mp3XingFrame.getFrameCount(); |
| 437 | |
} |
| 438 | 70 | else if (mp3VbriFrame != null) |
| 439 | |
{ |
| 440 | 4 | numberOfFrames = mp3VbriFrame.getFrameCount(); |
| 441 | |
} |
| 442 | |
else |
| 443 | |
{ |
| 444 | 66 | numberOfFrames = numberOfFramesEstimate; |
| 445 | |
} |
| 446 | |
|
| 447 | 2093 | } |
| 448 | |
|
| 449 | |
|
| 450 | |
|
| 451 | |
|
| 452 | |
public long getNumberOfFrames() |
| 453 | |
{ |
| 454 | 39 | return numberOfFrames; |
| 455 | |
} |
| 456 | |
|
| 457 | |
|
| 458 | |
|
| 459 | |
|
| 460 | |
|
| 461 | |
public long getNumberOfFramesEstimate() |
| 462 | |
{ |
| 463 | 0 | return numberOfFramesEstimate; |
| 464 | |
} |
| 465 | |
|
| 466 | |
|
| 467 | |
|
| 468 | |
|
| 469 | |
|
| 470 | |
|
| 471 | |
protected void setTimePerFrame() |
| 472 | |
{ |
| 473 | 2093 | timePerFrame = mp3FrameHeader.getNoOfSamples() / mp3FrameHeader.getSamplingRate().doubleValue(); |
| 474 | |
|
| 475 | |
|
| 476 | |
|
| 477 | 2093 | if ((mp3FrameHeader.getVersion() == MPEGFrameHeader.VERSION_2) || (mp3FrameHeader.getVersion() == MPEGFrameHeader.VERSION_2_5)) |
| 478 | |
{ |
| 479 | 64 | if ((mp3FrameHeader.getLayer() == MPEGFrameHeader.LAYER_II) || (mp3FrameHeader.getLayer() == MPEGFrameHeader.LAYER_III)) |
| 480 | |
{ |
| 481 | 64 | if (mp3FrameHeader.getNumberOfChannels() == 1) |
| 482 | |
{ |
| 483 | 52 | timePerFrame = timePerFrame / 2; |
| 484 | |
} |
| 485 | |
} |
| 486 | |
} |
| 487 | 2093 | } |
| 488 | |
|
| 489 | |
|
| 490 | |
|
| 491 | |
|
| 492 | |
private double getTimePerFrame() |
| 493 | |
{ |
| 494 | 2093 | return timePerFrame; |
| 495 | |
} |
| 496 | |
|
| 497 | |
|
| 498 | |
|
| 499 | |
|
| 500 | |
|
| 501 | |
|
| 502 | |
|
| 503 | |
|
| 504 | |
protected void setTrackLength() |
| 505 | |
{ |
| 506 | 2093 | trackLength = numberOfFrames * getTimePerFrame(); |
| 507 | 2093 | } |
| 508 | |
|
| 509 | |
|
| 510 | |
|
| 511 | |
|
| 512 | |
|
| 513 | |
public double getPreciseTrackLength() |
| 514 | |
{ |
| 515 | 135 | return trackLength; |
| 516 | |
} |
| 517 | |
|
| 518 | |
public int getTrackLength() |
| 519 | |
{ |
| 520 | 135 | return (int) getPreciseTrackLength(); |
| 521 | |
} |
| 522 | |
|
| 523 | |
|
| 524 | |
|
| 525 | |
|
| 526 | |
|
| 527 | |
public String getTrackLengthAsString() |
| 528 | |
{ |
| 529 | |
final Date timeIn; |
| 530 | |
try |
| 531 | |
{ |
| 532 | 135 | final long lengthInSecs = getTrackLength(); |
| 533 | 135 | synchronized(timeInFormat) |
| 534 | |
{ |
| 535 | 135 | timeIn = timeInFormat.parse(String.valueOf(lengthInSecs)); |
| 536 | 135 | } |
| 537 | |
|
| 538 | 135 | if (lengthInSecs < NO_SECONDS_IN_HOUR) |
| 539 | |
{ |
| 540 | 135 | synchronized(timeOutFormat) |
| 541 | |
{ |
| 542 | 135 | return timeOutFormat.format(timeIn); |
| 543 | 0 | } |
| 544 | |
} |
| 545 | |
else |
| 546 | |
{ |
| 547 | 0 | synchronized(timeOutOverAnHourFormat) |
| 548 | |
{ |
| 549 | 0 | return timeOutOverAnHourFormat.format(timeIn); |
| 550 | 0 | } |
| 551 | |
} |
| 552 | |
} |
| 553 | 0 | catch (ParseException pe) |
| 554 | |
{ |
| 555 | 0 | logger.warning("Unable to parse:"+getPreciseTrackLength() +" failed with ParseException:"+pe.getMessage()); |
| 556 | 0 | return ""; |
| 557 | |
} |
| 558 | |
} |
| 559 | |
|
| 560 | |
|
| 561 | |
|
| 562 | |
|
| 563 | |
public String getEncodingType() |
| 564 | |
{ |
| 565 | 52 | return TYPE_MP3; |
| 566 | |
} |
| 567 | |
|
| 568 | |
|
| 569 | |
|
| 570 | |
|
| 571 | |
protected void setBitRate() |
| 572 | |
{ |
| 573 | |
|
| 574 | 2093 | if (mp3XingFrame != null && mp3XingFrame.isVbr()) |
| 575 | |
{ |
| 576 | 33 | if (mp3XingFrame.isAudioSizeEnabled() && mp3XingFrame.getAudioSize() > 0) |
| 577 | |
{ |
| 578 | 33 | bitrate = (long) ((mp3XingFrame.getAudioSize() * CONVERTS_BYTE_TO_BITS) / (timePerFrame * getNumberOfFrames() * CONVERT_TO_KILOBITS)); |
| 579 | |
} |
| 580 | |
else |
| 581 | |
{ |
| 582 | 0 | bitrate = (long) (((fileSize - startByte) * CONVERTS_BYTE_TO_BITS) / (timePerFrame * getNumberOfFrames() * CONVERT_TO_KILOBITS)); |
| 583 | |
} |
| 584 | |
} |
| 585 | 2060 | else if (mp3VbriFrame != null) |
| 586 | |
{ |
| 587 | 4 | if (mp3VbriFrame.getAudioSize() > 0) |
| 588 | |
{ |
| 589 | 4 | bitrate = (long) ((mp3VbriFrame.getAudioSize() * CONVERTS_BYTE_TO_BITS) / (timePerFrame * getNumberOfFrames() * CONVERT_TO_KILOBITS)); |
| 590 | |
} |
| 591 | |
else |
| 592 | |
{ |
| 593 | 0 | bitrate = (long) (((fileSize - startByte) * CONVERTS_BYTE_TO_BITS) / (timePerFrame * getNumberOfFrames() * CONVERT_TO_KILOBITS)); |
| 594 | |
} |
| 595 | |
} |
| 596 | |
else |
| 597 | |
{ |
| 598 | 2056 | bitrate = mp3FrameHeader.getBitRate(); |
| 599 | |
} |
| 600 | 2093 | } |
| 601 | |
|
| 602 | |
protected void setEncoder() |
| 603 | |
{ |
| 604 | 2093 | if (mp3XingFrame != null) |
| 605 | |
{ |
| 606 | 2023 | if (mp3XingFrame.getLameFrame() != null) |
| 607 | |
{ |
| 608 | 2021 | encoder = mp3XingFrame.getLameFrame().getEncoder(); |
| 609 | |
} |
| 610 | |
} |
| 611 | 70 | else if (mp3VbriFrame != null) |
| 612 | |
{ |
| 613 | 4 | encoder = mp3VbriFrame.getEncoder(); |
| 614 | |
} |
| 615 | 2093 | } |
| 616 | |
|
| 617 | |
|
| 618 | |
|
| 619 | |
|
| 620 | |
public long getBitRateAsNumber() |
| 621 | |
{ |
| 622 | 2 | return bitrate; |
| 623 | |
} |
| 624 | |
|
| 625 | |
|
| 626 | |
|
| 627 | |
|
| 628 | |
|
| 629 | |
public String getBitRate() |
| 630 | |
{ |
| 631 | 52 | if (mp3XingFrame != null && mp3XingFrame.isVbr()) |
| 632 | |
{ |
| 633 | 24 | return isVbrIdentifier + String.valueOf(bitrate); |
| 634 | |
} |
| 635 | 28 | else if (mp3VbriFrame != null) |
| 636 | |
{ |
| 637 | 0 | return isVbrIdentifier + String.valueOf(bitrate); |
| 638 | |
} |
| 639 | |
else |
| 640 | |
{ |
| 641 | 28 | return String.valueOf(bitrate); |
| 642 | |
} |
| 643 | |
} |
| 644 | |
|
| 645 | |
|
| 646 | |
|
| 647 | |
|
| 648 | |
|
| 649 | |
public int getSampleRateAsNumber() |
| 650 | |
{ |
| 651 | 0 | return mp3FrameHeader.getSamplingRate(); |
| 652 | |
} |
| 653 | |
|
| 654 | |
|
| 655 | |
|
| 656 | |
|
| 657 | |
public String getSampleRate() |
| 658 | |
{ |
| 659 | 52 | return String.valueOf(mp3FrameHeader.getSamplingRate()); |
| 660 | |
} |
| 661 | |
|
| 662 | |
|
| 663 | |
|
| 664 | |
|
| 665 | |
public String getMpegVersion() |
| 666 | |
{ |
| 667 | 55 | return mp3FrameHeader.getVersionAsString(); |
| 668 | |
} |
| 669 | |
|
| 670 | |
|
| 671 | |
|
| 672 | |
|
| 673 | |
public String getMpegLayer() |
| 674 | |
{ |
| 675 | 55 | return mp3FrameHeader.getLayerAsString(); |
| 676 | |
} |
| 677 | |
|
| 678 | |
|
| 679 | |
|
| 680 | |
|
| 681 | |
public String getFormat() |
| 682 | |
{ |
| 683 | 0 | return mp3FrameHeader.getVersionAsString() + " " + mp3FrameHeader.getLayerAsString(); |
| 684 | |
} |
| 685 | |
|
| 686 | |
|
| 687 | |
|
| 688 | |
|
| 689 | |
public String getChannels() |
| 690 | |
{ |
| 691 | 55 | return mp3FrameHeader.getChannelModeAsString(); |
| 692 | |
} |
| 693 | |
|
| 694 | |
|
| 695 | |
|
| 696 | |
|
| 697 | |
public String getEmphasis() |
| 698 | |
{ |
| 699 | 0 | return mp3FrameHeader.getEmphasisAsString(); |
| 700 | |
} |
| 701 | |
|
| 702 | |
|
| 703 | |
|
| 704 | |
|
| 705 | |
public boolean isVariableBitRate() |
| 706 | |
{ |
| 707 | 54 | if (mp3XingFrame != null) |
| 708 | |
{ |
| 709 | 36 | return mp3XingFrame.isVbr(); |
| 710 | |
} |
| 711 | 18 | else if (mp3VbriFrame != null) |
| 712 | |
{ |
| 713 | 2 | return mp3VbriFrame.isVbr(); |
| 714 | |
} |
| 715 | |
else |
| 716 | |
{ |
| 717 | 16 | return mp3FrameHeader.isVariableBitRate(); |
| 718 | |
} |
| 719 | |
} |
| 720 | |
|
| 721 | |
public boolean isProtected() |
| 722 | |
{ |
| 723 | 52 | return mp3FrameHeader.isProtected(); |
| 724 | |
} |
| 725 | |
|
| 726 | |
public boolean isPrivate() |
| 727 | |
{ |
| 728 | 52 | return mp3FrameHeader.isPrivate(); |
| 729 | |
} |
| 730 | |
|
| 731 | |
public boolean isCopyrighted() |
| 732 | |
{ |
| 733 | 52 | return mp3FrameHeader.isCopyrighted(); |
| 734 | |
} |
| 735 | |
|
| 736 | |
public boolean isOriginal() |
| 737 | |
{ |
| 738 | 52 | return mp3FrameHeader.isOriginal(); |
| 739 | |
} |
| 740 | |
|
| 741 | |
public boolean isPadding() |
| 742 | |
{ |
| 743 | 0 | return mp3FrameHeader.isPadding(); |
| 744 | |
} |
| 745 | |
|
| 746 | |
|
| 747 | |
|
| 748 | |
|
| 749 | |
public String getEncoder() |
| 750 | |
{ |
| 751 | 54 | return encoder; |
| 752 | |
} |
| 753 | |
|
| 754 | |
|
| 755 | |
|
| 756 | |
|
| 757 | |
|
| 758 | |
|
| 759 | |
protected void setFileSize(long fileSize) |
| 760 | |
{ |
| 761 | 2093 | this.fileSize = fileSize; |
| 762 | 2093 | } |
| 763 | |
|
| 764 | |
|
| 765 | |
|
| 766 | |
|
| 767 | |
|
| 768 | |
public String toString() |
| 769 | |
{ |
| 770 | 95 | String s = "fileSize:" + fileSize + " encoder:" + encoder + " startByte:" + Hex.asHex(startByte) + " numberOfFrames:" + numberOfFrames + " numberOfFramesEst:" + numberOfFramesEstimate + " timePerFrame:" + timePerFrame + " bitrate:" + bitrate + " trackLength:" + getTrackLengthAsString(); |
| 771 | |
|
| 772 | 95 | if (this.mp3FrameHeader != null) |
| 773 | |
{ |
| 774 | 95 | s += mp3FrameHeader.toString(); |
| 775 | |
} |
| 776 | |
|
| 777 | 95 | if (this.mp3XingFrame != null) |
| 778 | |
{ |
| 779 | 80 | s += mp3XingFrame.toString(); |
| 780 | |
} |
| 781 | 95 | return s; |
| 782 | |
} |
| 783 | |
} |