POPMID3V2Framepublic class POPMID3V2Frame extends ID3V2Frame Frame containing a popularimeter. |
Fields Summary |
---|
private String | m_sEmailToUser | private int | m_iPopularity | private int | m_iPlayCount |
Constructors Summary |
---|
public POPMID3V2Frame(String sEmailToUser, int iPopularity, int iPlayCount)Creates a new instance of POPMID3V2Frame.
if ((sEmailToUser == null) || (sEmailToUser.length() == 0))
{
throw new ID3Exception("Email address is required in POPM frame.");
}
m_sEmailToUser = sEmailToUser;
if ((iPopularity < 0) || (iPopularity > 255))
{
throw new ID3Exception("Popularity must be between 0 and 255 in POPM frame.");
}
m_iPopularity = iPopularity;
if (iPlayCount < 0)
{
throw new ID3Exception("Play count cannot be negative in POPM frame.");
}
m_iPlayCount = iPlayCount;
| public POPMID3V2Frame(String sEmailToUser, int iPopularity)Creates a new instance of POPMID3V2Frame, not specifying the play count value.
if ((sEmailToUser == null) || (sEmailToUser.length() == 0))
{
throw new ID3Exception("Email address is required in POPM frame.");
}
m_sEmailToUser = sEmailToUser;
if ((iPopularity < 0) || (iPopularity > 255))
{
throw new ID3Exception("Popularity must be between 0 and 255 in POPM frame.");
}
m_iPopularity = iPopularity;
m_iPlayCount = -1;
| public POPMID3V2Frame(InputStream oIS)
try
{
ID3DataInputStream oFrameDataID3DIS = new ID3DataInputStream(oIS);
// email to user
m_sEmailToUser = oFrameDataID3DIS.readStringToNull();
// popularity
m_iPopularity = oFrameDataID3DIS.readUnsignedByte();
// play count (optional)
if (oFrameDataID3DIS.available() > 0)
{
if (oFrameDataID3DIS.available() == 4)
{
m_iPlayCount = oFrameDataID3DIS.readBE32();
}
else
{
// overflow (seriously, this will never _really_ happen...)
m_iPlayCount = Integer.MAX_VALUE;
}
}
else
{
// no play count
m_iPlayCount = -1;
}
}
catch (Exception e)
{
throw new InvalidFrameID3Exception(e);
}
|
Methods Summary |
---|
public void | accept(ID3Visitor oID3Visitor)
oID3Visitor.visitPOPMID3V2Frame(this);
| public boolean | equals(java.lang.Object oOther)
if ((oOther == null) || (!(oOther instanceof POPMID3V2Frame)))
{
return false;
}
POPMID3V2Frame oOtherPOPM = (POPMID3V2Frame)oOther;
return (m_sEmailToUser.equals(oOtherPOPM.m_sEmailToUser) &&
(m_iPopularity == oOtherPOPM.m_iPopularity) &&
(m_iPlayCount == oOtherPOPM.m_iPlayCount));
| public java.lang.String | getEmailToUser()Get the email address of the user to be informed about the popularity of this track.
return m_sEmailToUser;
| protected byte[] | getFrameId()
return "POPM".getBytes();
| public int | getPlayCount()Get the play count value for this track.
return m_iPlayCount;
| public int | getPopularity()Get the popularity rating of this track (1=worst, 255=best, 0=unknown)
return m_iPopularity;
| public void | setPopularity(java.lang.String sEmailToUser, int iPopularity, int iPlayCount)Set the popularity values for this frame.
String sOrigEmailToUser = m_sEmailToUser;
int iOrigPopularity = m_iPopularity;
int iOrigPlayCount = m_iPlayCount;
if ((sEmailToUser == null) || (sEmailToUser.length() == 0))
{
throw new ID3Exception("Email address is required in POPM frame.");
}
if ((iPopularity < 0) || (iPopularity > 255))
{
throw new ID3Exception("Popularity must be between 0 and 255 in POPM frame.");
}
if (iPlayCount < 0)
{
throw new ID3Exception("Play count cannot be negative in POPM frame.");
}
m_sEmailToUser = sEmailToUser;
m_iPopularity = iPopularity;
m_iPlayCount = iPlayCount;
// try this update, and reverse it if it generates and error
try
{
notifyID3Observers();
}
catch (ID3Exception e)
{
m_sEmailToUser = sOrigEmailToUser;
m_iPopularity = iOrigPopularity;
m_iPlayCount = iOrigPlayCount;
throw e;
}
| public void | setPopularity(java.lang.String sEmailToUser, int iPopularity)Set the popularity values for this frame, not specifying a play count value.
String sOrigEmailToUser = m_sEmailToUser;
int iOrigPopularity = m_iPopularity;
int iOrigPlayCount = m_iPlayCount;
if ((sEmailToUser == null) || (sEmailToUser.length() == 0))
{
throw new ID3Exception("Email address is required in POPM frame.");
}
if ((iPopularity < 0) || (iPopularity > 255))
{
throw new ID3Exception("Popularity must be between 0 and 255 in POPM frame.");
}
m_sEmailToUser = sEmailToUser;
m_iPopularity = iPopularity;
m_iPlayCount = -1;
// try this update, and reverse it if it generates and error
try
{
notifyID3Observers();
}
catch (ID3Exception e)
{
m_sEmailToUser = sOrigEmailToUser;
m_iPopularity = iOrigPopularity;
m_iPlayCount = iOrigPlayCount;
throw e;
}
| public java.lang.String | toString()
return "Popularimeter: Email To User=[" + m_sEmailToUser + "], Popularity=" + m_iPopularity +
"], Play Count=[" + m_iPlayCount + "]";
| protected void | writeBody(ID3DataOutputStream oIDOS)
// email address plus null
oIDOS.write(m_sEmailToUser.getBytes());
oIDOS.write(0);
// popularity
oIDOS.write(m_iPopularity);
// play count
if (m_iPlayCount >= 0)
{
oIDOS.writeBE32(m_iPlayCount);
}
|
|