⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 flactag.java

📁 java+eclipse做的TTPlayer
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     * @return <code>true</code> if tag contains no field.
     */
    public boolean isEmpty()
    {
        return (tag==null||tag.isEmpty()) && images.size()==0;
    }

    /**
     *
     * @param field
     * @throws FieldDataInvalidException
     */
    public void set(TagField field)  throws FieldDataInvalidException
    {
        if(field instanceof MetadataBlockDataPicture)
        {
            if(images.size()==0)
            {
                images.add(0,(MetadataBlockDataPicture)field);   
            }
            else
            {
                images.set(0,(MetadataBlockDataPicture)field);
            }
        }
        else
        {
            tag.set(field);
        }
    }

    /**
     *
     * @param s
     * @throws FieldDataInvalidException
     */
    public void setAlbum(String s)  throws FieldDataInvalidException
    {
        tag.setAlbum(s);
    }


    /**
     *
     * @param s
     * @throws FieldDataInvalidException
     */
    public void setArtist(String s)  throws FieldDataInvalidException
    {
        tag.setArtist(s);
    }

    /**
     *
     * @param s
     * @throws FieldDataInvalidException
     */
    public void setComment(String s)  throws FieldDataInvalidException
    {
        tag.setComment(s);
    }


    /**
     *
     * @param s
     * @throws FieldDataInvalidException
     */
    public void setGenre(String s)  throws FieldDataInvalidException
    {
        tag.setGenre(s);
    }

    /**
     *
     * @param s
     * @throws FieldDataInvalidException
     */
    public void setTitle(String s)  throws FieldDataInvalidException
    {
        tag.setTitle(s);
    }

    /**
     *
     * @param s
     * @throws FieldDataInvalidException
     */
    public void setTrack(String s)   throws FieldDataInvalidException
    {
        tag.setTrack(s);
    }

    /**
     *
     * @param s
     * @throws FieldDataInvalidException
     */
    public void setYear(String s)  throws FieldDataInvalidException
    {
        tag.setYear(s);
    }


    /**
     * Create a new TagField based on generic key
     *
     * <p>Only textual data supported at the moment. The genericKey will be mapped
     * to the correct implementation key and return a TagField.
     *
     * @param genericKey is the generic key
     * @param value to store
     * @return
     */
    public TagField createTagField(TagFieldKey genericKey,String value)
        throws KeyNotFoundException,FieldDataInvalidException
    {
        if(genericKey.equals(TagFieldKey.COVER_ART))
        {
            throw new UnsupportedOperationException("Please use the createArtworkField methods to create coverart ");
        }
        else
        {
            return tag.createTagField(genericKey,value);
        }
    }



    /**
     * Retrieve the first value that exists for this key
     *
     * @param id
     * @return
     */
    public String getFirst(String id)
    {
        if(id.equals(TagFieldKey.COVER_ART.name()))
        {
            throw new UnsupportedOperationException("Please use the createArtworkField methods to create coverart ");
        }
        else
        {
            return tag.getFirst(id);
        }
    }

    /**
     * Retrieve String value of first tagfield that exists for this key
     *
     * @param id
     * @return String value or empty string
     */
    public String getFirst(TagFieldKey id)
            throws KeyNotFoundException
    {
        if(id.equals(TagFieldKey.COVER_ART))
        {
            throw new UnsupportedOperationException("Please use the createArtworkField methods to create coverart ");
        }
        else
        {
            return tag.getFirst(id);
        }

    }

    /**
     * Retrieve the first tagfield that exists for this key
     *
     * <p>Can be used to retrieve fields with any identifier, useful if the identifier is not within  the
     * jaudiotagger enum
     *
     * @param id audio specific key
     * @return tag field or null if doesnt exist
     */
    public TagField getFirstField(String id)
    {
        if(id.equals(TagFieldKey.COVER_ART))
        {
            if(images.size()>0)
            {
                return images.get(0);
            }
            else
            {
                return null;
            }
        }
        else
        {
             return tag.getFirstField(id);
        }
    }


    /**
     * Delete any instance of tag fields with this key
     *
     * @param tagFieldKey
     */
    public void deleteTagField(TagFieldKey tagFieldKey)
            throws KeyNotFoundException
    {
        if(tagFieldKey.equals(TagFieldKey.COVER_ART))
        {
            images.clear();
        }
        else
        {
             tag.deleteTagField(tagFieldKey);
        }
    }

    /**
     * Iterator over all the fields within the tag, handle multiple fields with the same id
     *
     * @return iterator over whole list
     */
    //TODO add images to iterator
    public Iterator getFields()
    {
        return tag.getFields();
    }

    /**
       * Return the number of fields
       *
       * <p>Fields with the same identifiers are counted seperately
       * i.e two title fields would contribute two to the count
       *
       * @return total number of fields
       */
      public int getFieldCount()
      {
          return tag.getFieldCount() + images.size();
      }

      public boolean setEncoding(String enc)  throws FieldDataInvalidException
      {
          return tag.setEncoding(enc);
      }

    /**
        * Returns a {@linkplain List list} of {@link TagField} objects whose &quot;{@linkplain TagField#getId() id}&quot;
        * is the specified one.<br>
        *
        * @param id
        *            The field id.
        * @return A list of {@link TagField} objects with the given &quot;id&quot;.
        */
   public List<TagField> get(TagFieldKey id)
               throws KeyNotFoundException
    {
        if(id.equals(TagFieldKey.COVER_ART))
        {
            List <TagField> castImages = new ArrayList<TagField>();
            for(MetadataBlockDataPicture image:images)
            {
                castImages.add(image);
            }
            return castImages;
        }
        else
        {
             return tag.get(id);
        }

    }

    /**
     * Create Artwork when have the raw image data
     *
     * @param imageData
     * @param pictureType
     * @param mimeType
     * @param description
     * @param width
     * @param height
     * @param colourDepth
     * @param indexedColouredCount
     * @return
     * @throws FieldDataInvalidException
     */
    public TagField createArtworkField(byte[] imageData,
                                    int pictureType,
                                    String mimeType,
                                    String description,
                                    int width,
                                    int height,
                                    int colourDepth,
                                    int indexedColouredCount
     )  throws FieldDataInvalidException
    {
        return new MetadataBlockDataPicture(imageData,
                                    pictureType,
                                    mimeType,
                                    description,
                                    width,
                                    height,
                                    colourDepth,
                                    indexedColouredCount);
    }

    /**
     * Create Artwork when  have the bufferedimage
     *                                              
     * @param pictureType
     * @param mimeType
     * @param description
     * @param colourDepth
     * @param indexedColouredCount
     * @return
     * @throws FieldDataInvalidException
     */
    public TagField createArtworkField(BufferedImage bi,
                                    int pictureType,
                                    String mimeType,
                                    String description,                                   
                                    int colourDepth,
                                    int indexedColouredCount
     )  throws FieldDataInvalidException
    {
         //Convert to byte array
        try
        {
            final ByteArrayOutputStream output = new ByteArrayOutputStream();
            ImageIO.write(bi, ImageFormats.getFormatForMimeType(mimeType),new DataOutputStream(output));

            //Add to image list
            return new MetadataBlockDataPicture(output.toByteArray(),
                                    pictureType,
                                    mimeType,
                                    description,
                                    bi.getWidth(),
                                    bi.getHeight(),
                                    colourDepth,
                                    indexedColouredCount);
        }
        catch(IOException ioe)
        {
            throw new FieldDataInvalidException("Unable to convert image to bytearray, check mimetype parameter");
        }
    }

    /**
    * Create Link to Image File, not recommended because if either flac or image file is moved link
    * will be broken.
    */ 
    public TagField createLinkedArtworkField(String url)
    {
        //Add to image list
        return new MetadataBlockDataPicture(Utils.getDefaultBytes(url,TextEncoding.CHARSET_ISO_8859_1),
                                    PictureTypes.DEFAULT_ID,
                                    MetadataBlockDataPicture.IMAGE_IS_URL,
                                    "",
                                    0,
                                    0,
                                    0,
                                    0);
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -