| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| FrameBodyPCNT |
|
| 1.0;1 |
| 1 | /* | |
| 2 | * MusicTag Copyright (C)2003,2004 | |
| 3 | * | |
| 4 | * This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser | |
| 5 | * General Public License as published by the Free Software Foundation; either version 2.1 of the License, | |
| 6 | * or (at your option) any later version. | |
| 7 | * | |
| 8 | * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even | |
| 9 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | |
| 10 | * See the GNU Lesser General Public License for more details. | |
| 11 | * | |
| 12 | * You should have received a copy of the GNU Lesser General Public License along with this library; if not, | |
| 13 | * you can get a copy from http://www.opensource.org/licenses/lgpl-license.php or write to the Free Software | |
| 14 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 15 | */ | |
| 16 | package org.jaudiotagger.tag.id3.framebody; | |
| 17 | ||
| 18 | import org.jaudiotagger.tag.InvalidTagException; | |
| 19 | import org.jaudiotagger.tag.datatype.DataTypes; | |
| 20 | import org.jaudiotagger.tag.datatype.NumberVariableLength; | |
| 21 | import org.jaudiotagger.tag.id3.ID3v24Frames; | |
| 22 | ||
| 23 | import java.nio.ByteBuffer; | |
| 24 | ||
| 25 | /** | |
| 26 | * Play counter frame. | |
| 27 | * <p/> | |
| 28 | * <p/> | |
| 29 | * This is simply a counter of the number of times a file has been | |
| 30 | * played. The value is increased by one every time the file begins to | |
| 31 | * play. There may only be one "PCNT" frame in each tag. When the | |
| 32 | * counter reaches all one's, one byte is inserted in front of the | |
| 33 | * counter thus making the counter eight bits bigger. The counter must | |
| 34 | * be at least 32-bits long to begin with. | |
| 35 | * </p><p><table border=0 width="70%"> | |
| 36 | * <tr><td colspan=2> <Header for 'Play counter', ID: "PCNT"></td></tr> | |
| 37 | * <tr><td>Counter </td><td>$xx xx xx xx (xx ...)</td></tr> | |
| 38 | * </table></p> | |
| 39 | * <p/> | |
| 40 | * <p>For more details, please refer to the ID3 specifications: | |
| 41 | * <ul> | |
| 42 | * <li><a href="http://www.id3.org/id3v2.3.0.txt">ID3 v2.3.0 Spec</a> | |
| 43 | * </ul> | |
| 44 | * | |
| 45 | * @author : Paul Taylor | |
| 46 | * @author : Eric Farng | |
| 47 | * @version $Id: FrameBodyPCNT.java 832 2009-11-12 13:25:38Z paultaylor $ | |
| 48 | */ | |
| 49 | public class FrameBodyPCNT extends AbstractID3v2FrameBody implements ID3v24FrameBody, ID3v23FrameBody | |
| 50 | { | |
| 51 | private static final int COUNTER_MINIMUM_FIELD_SIZE = 4; | |
| 52 | ||
| 53 | /** | |
| 54 | * Creates a new FrameBodyPCNT datatype. | |
| 55 | */ | |
| 56 | public FrameBodyPCNT() | |
| 57 | 24 | { |
| 58 | 24 | this.setObjectValue(DataTypes.OBJ_NUMBER, 0L); |
| 59 | 24 | } |
| 60 | ||
| 61 | public FrameBodyPCNT(FrameBodyPCNT body) | |
| 62 | { | |
| 63 | 0 | super(body); |
| 64 | 0 | } |
| 65 | ||
| 66 | /** | |
| 67 | * Creates a new FrameBodyPCNT datatype. | |
| 68 | * | |
| 69 | * @param counter | |
| 70 | */ | |
| 71 | public FrameBodyPCNT(long counter) | |
| 72 | 16 | { |
| 73 | 16 | this.setObjectValue(DataTypes.OBJ_NUMBER, counter); |
| 74 | 16 | } |
| 75 | ||
| 76 | /** | |
| 77 | * Creates a new FrameBodyPCNT datatype. | |
| 78 | * | |
| 79 | * @param byteBuffer | |
| 80 | * @param frameSize | |
| 81 | * @throws InvalidTagException if unable to create framebody from buffer | |
| 82 | */ | |
| 83 | public FrameBodyPCNT(ByteBuffer byteBuffer, int frameSize) throws InvalidTagException | |
| 84 | { | |
| 85 | 8 | super(byteBuffer, frameSize); |
| 86 | 8 | } |
| 87 | ||
| 88 | /** | |
| 89 | * @return the play count of this file | |
| 90 | */ | |
| 91 | public long getCounter() | |
| 92 | { | |
| 93 | 24 | return ((Number) getObjectValue(DataTypes.OBJ_NUMBER)).longValue(); |
| 94 | } | |
| 95 | ||
| 96 | /** | |
| 97 | * Set the play counter of this file | |
| 98 | * | |
| 99 | * @param counter | |
| 100 | */ | |
| 101 | public void setCounter(long counter) | |
| 102 | { | |
| 103 | 4 | setObjectValue(DataTypes.OBJ_NUMBER, counter); |
| 104 | 4 | } |
| 105 | ||
| 106 | /** | |
| 107 | * The ID3v2 frame identifier | |
| 108 | * | |
| 109 | * @return the ID3v2 frame identifier for this frame type | |
| 110 | */ | |
| 111 | public String getIdentifier() | |
| 112 | { | |
| 113 | 40 | return ID3v24Frames.FRAME_ID_PLAY_COUNTER; |
| 114 | } | |
| 115 | ||
| 116 | /** | |
| 117 | * | |
| 118 | */ | |
| 119 | protected void setupObjectList() | |
| 120 | { | |
| 121 | 48 | objectList.add(new NumberVariableLength(DataTypes.OBJ_NUMBER, this, COUNTER_MINIMUM_FIELD_SIZE)); |
| 122 | 48 | } |
| 123 | } |