Exemple #1
0
  public void setField(TagField field) {
    FieldKey genericKey = FieldKey.valueOf(field.getId());
    switch (genericKey) {
      case ARTIST:
        setArtist(field.toString());
        break;

      case ALBUM:
        setAlbum(field.toString());
        break;

      case TITLE:
        setTitle(field.toString());
        break;

      case GENRE:
        setGenre(field.toString());
        break;

      case YEAR:
        setYear(field.toString());
        break;

      case COMMENT:
        setComment(field.toString());
        break;
    }
  }
 /**
  * Add Field
  *
  * <p>
  *
  * <p>Overidden because there can only be one vendor set
  *
  * @param field
  */
 public void addField(TagField field) {
   if (field.getId().equals(VorbisCommentFieldKey.VENDOR.getFieldName())) {
     super.setField(field);
   } else {
     super.addField(field);
   }
 }
  /** Lets now check the value explicity are what we expect */
  public void testTagFieldKeyWrite2() {
    Exception exceptionCaught = null;
    try {
      File testFile = AbstractTestCase.copyAudioToTmp("test1.wma", new File("testwrite1.wma"));
      AudioFile f = AudioFileIO.read(testFile);
      AudioFileIO.delete(f);

      // test fields are written with correct ids
      f = AudioFileIO.read(testFile);
      Tag tag = f.getTag();
      for (FieldKey key : FieldKey.values()) {
        if (!(key == FieldKey.COVER_ART)) {
          tag.addField(tag.createField(key, key.name() + "_value"));
        }
      }
      f.commit();

      // Reread File
      f = AudioFileIO.read(testFile);
      tag = f.getTag();

      TagField tf = tag.getFirstField(AsfFieldKey.ALBUM.getFieldName());
      assertEquals("WM/AlbumTitle", tf.getId());
      assertEquals("ALBUM_value", ((TagTextField) tf).getContent());
      assertEquals("UTF-16LE", ((TagTextField) tf).getEncoding());

      tf = tag.getFirstField(AsfFieldKey.ALBUM_ARTIST.getFieldName());
      assertEquals("WM/AlbumArtist", tf.getId());
      assertEquals("ALBUM_ARTIST_value", ((TagTextField) tf).getContent());
      assertEquals("UTF-16LE", ((TagTextField) tf).getEncoding());

      tf = tag.getFirstField(AsfFieldKey.AMAZON_ID.getFieldName());
      assertEquals("ASIN", tf.getId());
      assertEquals("AMAZON_ID_value", ((TagTextField) tf).getContent());
      assertEquals("UTF-16LE", ((TagTextField) tf).getEncoding());

      tf = tag.getFirstField(AsfFieldKey.TITLE.getFieldName());
      assertEquals("TITLE", tf.getId());
      assertEquals("TITLE_value", ((TagTextField) tf).getContent());
      assertEquals("UTF-16LE", ((TagTextField) tf).getEncoding());

    } catch (Exception e) {
      e.printStackTrace();
      exceptionCaught = e;
    }
    assertNull(exceptionCaught);
  }
Exemple #4
0
 public void setField(TagField field) {
   FieldKey genericKey = FieldKey.valueOf(field.getId());
   if (genericKey == FieldKey.TRACK) {
     setTrack(field.toString());
   } else {
     super.setField(field);
   }
 }
  public void testReadFileWithJpgArtwork() {
    File orig = new File("testdata", "test6.wma");
    if (!orig.isFile()) {
      System.err.println("Unable to test file - not available");
      return;
    }

    Exception exceptionCaught = null;
    try {
      File testFile = AbstractTestCase.copyAudioToTmp("test6.wma");
      AudioFile f = AudioFileIO.read(testFile);
      Tag tag = f.getTag();
      assertEquals(1, tag.getFields(FieldKey.COVER_ART).size());

      TagField tagField = tag.getFields(FieldKey.COVER_ART).get(0);
      assertEquals("WM/Picture", tagField.getId());
      assertEquals(5093, tagField.getRawContent().length);

      // Should have been loaded as special field to make things easier
      assertTrue(tagField instanceof AsfTagCoverField);
      AsfTagCoverField coverartField = (AsfTagCoverField) tagField;
      assertEquals("image/jpeg", coverartField.getMimeType());
      assertEquals("coveerart", coverartField.getDescription());
      assertEquals(3, coverartField.getPictureType());
      assertEquals(200, coverartField.getImage().getWidth());
      assertEquals(200, coverartField.getImage().getHeight());
      assertEquals(5093, coverartField.getRawContent().length);
      assertEquals(5046, coverartField.getRawImageData().length);
      assertEquals(5046, coverartField.getImageDataSize());
      assertEquals(coverartField.getRawImageData().length, coverartField.getImageDataSize());

      assertEquals(BufferedImage.TYPE_3BYTE_BGR, coverartField.getImage().getType());

      /** *** TO SOME MANUAL CHECKING **************** */

      // First byte of data is immediatley after the 2 byte Descriptor value
      assertEquals(0x03, tagField.getRawContent()[0]);
      // Raw Data consists of Unknown/MimeType/Name and Actual Image, null seperated  (two bytes)

      // Skip first three unknown bytes plus two byte nulls
      int count = 5;
      String mimeType = null;
      String name = null;
      int endOfMimeType = 0;
      int endOfName = 0;
      while (count < tagField.getRawContent().length - 1) {
        if (tagField.getRawContent()[count] == 0 && tagField.getRawContent()[count + 1] == 0) {
          if (mimeType == null) {
            mimeType = new String(tagField.getRawContent(), 5, (count) - 5, "UTF-16LE");
            endOfMimeType = count + 2;
          } else if (name == null) {
            name =
                new String(
                    tagField.getRawContent(), endOfMimeType, count - endOfMimeType, "UTF-16LE");
            endOfName = count + 2;
            break;
          }
          count += 2;
        }
        count += 2; // keep on two byte word boundary
      }

      assertEquals("image/jpeg", mimeType);
      assertEquals("coveerart", name);

      BufferedImage bi =
          ImageIO.read(
              ImageIO.createImageInputStream(
                  new ByteArrayInputStream(
                      tagField.getRawContent(),
                      endOfName,
                      tagField.getRawContent().length - endOfName)));
      assertNotNull(bi);
      assertEquals(200, bi.getWidth());
      assertEquals(200, bi.getHeight());
      assertEquals(BufferedImage.TYPE_3BYTE_BGR, bi.getType());

    } catch (Exception e) {
      e.printStackTrace();
      exceptionCaught = e;
    }
    assertNull(exceptionCaught);
  }