1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
|
/***************************************************************************
copyright : (C) 2005 by Brian Nickel
email : brian.nickel@gmail.com
based on :
***************************************************************************/
/***************************************************************************
* This library is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License version *
* 2.1 as published by the Free Software Foundation. *
* *
* This library is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with this library; if not, write to the Free Software *
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
* USA *
***************************************************************************/
using System.Collections;
using System;
namespace TagLib.Asf
{
[SupportedMimeType("taglib/wma", "wma")]
[SupportedMimeType("taglib/asf", "asf")]
[SupportedMimeType("audio/x-ms-wma")]
[SupportedMimeType("video/x-ms-asf")]
public class File : TagLib.File
{
//////////////////////////////////////////////////////////////////////////
// private properties
//////////////////////////////////////////////////////////////////////////
private Asf.Tag asf_tag;
private Properties properties;
//////////////////////////////////////////////////////////////////////////
// public methods
//////////////////////////////////////////////////////////////////////////
public File (string file, Properties.ReadStyle properties_style) : base (file)
{
asf_tag = null;
properties = null;
try {Mode = AccessMode.Read;}
catch {return;}
Read (properties_style);
Mode = AccessMode.Closed;
}
public File (string file) : this (file, Properties.ReadStyle.Average)
{
}
public override void Save ()
{
if(IsReadOnly) {
throw new ReadOnlyException();
}
Mode = AccessMode.Write;
HeaderObject header = new HeaderObject (this, 0);
header.AddUniqueObject (asf_tag.ContentDescriptionObject);
header.AddUniqueObject (asf_tag.ExtendedContentDescriptionObject);
Insert (header.Render (), 0, header.OriginalSize);
Mode = AccessMode.Closed;
}
public override TagLib.Tag GetTag (TagTypes type, bool create)
{
if (type == TagTypes.Asf)
return asf_tag;
return null;
}
public short ReadWord ()
{
ByteVector v = ReadBlock (2);
return v.ToShort (false);
}
public uint ReadDWord ()
{
ByteVector v = ReadBlock (4);
return v.ToUInt (false);
}
public long ReadQWord ()
{
ByteVector v = ReadBlock (8);
return v.ToLong (false);
}
public Guid ReadGuid ()
{
ByteVector v = ReadBlock (16);
return new Guid (v);
}
public string ReadUnicode (int length)
{
ByteVector data = ReadBlock (length);
string output = data.ToString (StringType.UTF16LE);
int i = output.IndexOf ('\0');
return (i >= 0) ? output.Substring (0, i) : output;
}
public Object [] ReadObjects (uint count, long position)
{
ArrayList l = new ArrayList ();
for (int i = 0; i < (int) count; i ++)
{
Seek (position);
Guid id = ReadGuid ();
Object obj;
if (id.Equals (Guid.AsfFilePropertiesObject))
obj = new FilePropertiesObject (this, position);
else if (id.Equals (Guid.AsfStreamPropertiesObject))
obj = new StreamPropertiesObject (this, position);
else if (id.Equals (Guid.AsfContentDescriptionObject))
obj = new ContentDescriptionObject (this, position);
else if (id.Equals (Guid.AsfExtendedContentDescriptionObject))
obj = new ExtendedContentDescriptionObject (this, position);
else if (id.Equals (Guid.AsfPaddingObject))
obj = new PaddingObject (this, position);
else
obj = new UnknownObject (this, position);
l.Add (obj);
position += obj.OriginalSize;
}
return (Object []) l.ToArray (typeof (Object));
}
//////////////////////////////////////////////////////////////////////////
// public properties
//////////////////////////////////////////////////////////////////////////
public override TagLib.Tag Tag {get {return asf_tag;}}
public override TagLib.AudioProperties AudioProperties {get {return properties;}}
//////////////////////////////////////////////////////////////////////////
// private methods
//////////////////////////////////////////////////////////////////////////
private void Read (Properties.ReadStyle properties_style)
{
HeaderObject header = new HeaderObject (this, 0);
asf_tag = new Asf.Tag (header);
if(properties_style != Properties.ReadStyle.None)
properties = new Properties (header, properties_style);
}
}
}
|