| 1 | package org.farng.mp3.id3; |
| 2 | |
| 3 | import org.farng.mp3.InvalidTagException; |
| 4 | import org.farng.mp3.object.ObjectByteArraySizeTerminated; |
| 5 | import org.farng.mp3.object.ObjectNumberHashMap; |
| 6 | import org.farng.mp3.object.ObjectStringNullTerminated; |
| 7 | |
| 8 | import java.io.IOException; |
| 9 | import java.io.RandomAccessFile; |
| 10 | |
| 11 | /** |
| 12 | * <h3>4.14. Attached picture</h3> |
| 13 | * <p/> |
| 14 | * <p> This frame contains a picture directly related to the audio file.<br> Image format is |
| 15 | * the MIME type and subtype [MIME] for the image. In<br> the event that the MIME media type name is |
| 16 | * omitted, "image/" will be<br> |
| 17 | * <p/> |
| 18 | * implied. The "image/png" [PNG] or "image/jpeg" [JFIF] picture format<br> |
| 19 | * should be used when interoperability is wanted. Description is a<br> short description of |
| 20 | * the picture, represented as a terminated<br> |
| 21 | * <p/> |
| 22 | * text string. There may be several pictures attached to one file, each<br> in their |
| 23 | * individual "APIC" frame, but only one with the same content<br> descriptor. There may only be |
| 24 | * one picture with the picture type<br> declared as picture type $01 and $02 respectively. There is |
| 25 | * the<br> |
| 26 | * <p/> |
| 27 | * possibility to put only a link to the image file by using the 'MIME<br> type' |
| 28 | * "-->" and having a complete URL [URL] instead of picture data.<br> The use of linked files |
| 29 | * should however be used sparingly since there<br> is the risk of separation of files.</p> |
| 30 | * <p/> |
| 31 | * <p> <Header for 'Attached picture', ID: "APIC"><br> |
| 32 | * Text encoding $xx<br> MIME |
| 33 | * type <text string> |
| 34 | * <p/> |
| 35 | * $00<br> Picture type $xx<br> |
| 36 | * Description <text string according to encoding> $00 (00)<br> |
| 37 | * <p/> |
| 38 | * Picture data <binary data><br> </p> |
| 39 | * <p/> |
| 40 | * <p> Picture type: $00 Other<br> |
| 41 | * <p/> |
| 42 | * $01 32x32 pixels 'file icon' (PNG only)<br> |
| 43 | * $02 Other file icon<br> |
| 44 | * $03 Cover (front)<br> |
| 45 | * <p/> |
| 46 | * $04 |
| 47 | * Cover (back)<br> |
| 48 | * $05 Leaflet page<br> |
| 49 | * $06 Media (e.g. label side of CD)<br> |
| 50 | * <p/> |
| 51 | * $07 Lead |
| 52 | * artist/lead performer/soloist<br> |
| 53 | * $08 Artist/performer<br> |
| 54 | * $09 Conductor<br> |
| 55 | * <p/> |
| 56 | * $0A |
| 57 | * Band/Orchestra<br> |
| 58 | * $0B Composer<br> |
| 59 | * $0C Lyricist/text writer<br> |
| 60 | * <p/> |
| 61 | * $0D |
| 62 | * Recording Location<br> |
| 63 | * $0E During recording<br> |
| 64 | * $0F During performance<br> |
| 65 | * <p/> |
| 66 | * $10 |
| 67 | * Movie/video screen capture<br> |
| 68 | * $11 A bright coloured fish<br> |
| 69 | * $12 Illustration<br> |
| 70 | * <p/> |
| 71 | * $13 |
| 72 | * Band/artist logotype<br> |
| 73 | * $14 Publisher/Studio logotype<br> </p> |
| 74 | * |
| 75 | * @author Eric Farng |
| 76 | * @version $Revision: 1.4 $ |
| 77 | */ |
| 78 | public class FrameBodyAPIC extends AbstractID3v2FrameBody { |
| 79 | |
| 80 | /** |
| 81 | * Creates a new FrameBodyAPIC object. |
| 82 | */ |
| 83 | public FrameBodyAPIC() { |
| 84 | super(); |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * Creates a new FrameBodyAPIC object. |
| 89 | */ |
| 90 | public FrameBodyAPIC(final FrameBodyAPIC body) { |
| 91 | super(body); |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * Creates a new FrameBodyAPIC object. |
| 96 | */ |
| 97 | public FrameBodyAPIC(final byte textEncoding, |
| 98 | final String mimeType, |
| 99 | final byte pictureType, |
| 100 | final String description, |
| 101 | final byte[] data) { |
| 102 | super(); |
| 103 | setObject("Text Encoding", new Byte(textEncoding)); |
| 104 | setObject("MIME Type", mimeType); |
| 105 | setObject("Picture Type", new Byte(pictureType)); |
| 106 | setObject("Description", description); |
| 107 | setObject("Picture Data", data); |
| 108 | } |
| 109 | |
| 110 | /** |
| 111 | * Creates a new FrameBodyAPIC object. |
| 112 | */ |
| 113 | public FrameBodyAPIC(final RandomAccessFile file) throws IOException, InvalidTagException { |
| 114 | super(); |
| 115 | read(file); |
| 116 | } |
| 117 | |
| 118 | public void setDescription(final String description) { |
| 119 | setObject("Description", description); |
| 120 | } |
| 121 | |
| 122 | public String getDescription() { |
| 123 | return (String) getObject("Description"); |
| 124 | } |
| 125 | |
| 126 | public String getIdentifier() { |
| 127 | return "APIC" + (char) 0 + getDescription(); |
| 128 | } |
| 129 | |
| 130 | protected void setupObjectList() { |
| 131 | appendToObjectList(new ObjectNumberHashMap("Text Encoding", 1)); |
| 132 | appendToObjectList(new ObjectStringNullTerminated("MIME Type")); |
| 133 | appendToObjectList(new ObjectStringNullTerminated("Description")); |
| 134 | appendToObjectList(new ObjectByteArraySizeTerminated("Picture Data")); |
| 135 | } |
| 136 | } |