| Author |
Message |
Alessandro Angeli [MVP::D
Guest
|
Posted:
Wed Oct 06, 2004 10:20 pm Post subject:
Re: About obscurity of some extended attributes structures d |
|
|
Vincas Stepankevicius wrote:
| Quote: | Thanks in advance, Alessandro, I'll be eager waiting for
evening :) Meanwhile I'm remastering my app applying new
knowledge I've bought from you for Robert's money ;)
|
Added the code to add a new WM/Lyrics_Synchronised
attribute. There are more effient ways to do this: remember
you can copy whole array back and forth from managed arrays
and unmanaged memory buffers using the Marshal.Copy() family
of methods.
------------------------------------------
IMPORTS System
IMPORTS System.IO
IMPORTS System.Runtime.InteropServices
IMPORTS WMFSDKWrapper
PUBLIC MODULE slyr
SUB Main()
TRY
DIM pEditor AS IWMMetadataEditor
WMFSDKFunctions.WMCreateEditor(pEditor)
pEditor.Open("x.wma")
DIM pHeader AS IWMHeaderInfo3 = pEditor
DIM wStream AS UInt16
DIM wCount AS UInt16
pHeader.GetAttributeCountEx(wStream,wCount)
FOR i AS Integer = 0 TO Convert.ToInt32(wCount)-1
DIM dtType AS WMT_ATTR_DATATYPE
DIM wLang AS UInt16
DIM szName AS String = Nothing
DIM pbData() AS Byte = Nothing
DIM wName AS UInt16
DIM dwData AS UInt32
pHeader.GetAttributeByIndexEx(wStream,Convert.ToUInt16(i),sz
Name,wName,dtType,wLang,pbData,dwData)
szName = NEW String("0",Convert.ToInt32(wName)-1)
REDIM pbData(Convert.ToInt32(dwData))
pHeader.GetAttributeByIndexEx(wStream,Convert.ToUInt16(i),sz
Name,wName,dtType,wLang,pbData,dwData)
Console.WriteLine(">>> ""{0}""",szName)
DIM pStream AS MemoryStream = NEW MemoryStream(pbData)
DIM pReader AS BinaryReader = NEW BinaryReader(pStream)
DIM _ptr, _end AS Integer
IF szName = "WM/Lyrics_Synchronised" THEN
Console.WriteLine(">>> bTimeStampFormat .... =
{0}",pReader.ReadByte())
Console.WriteLine(">>> bContentType ........ =
{0}",pReader.ReadByte())
Console.WriteLine(">>> pwszContentDescriptor =
L""{0}""",Marshal.PtrToStringUni(NEW
IntPtr(pReader.ReadInt32())))
_end = pReader.ReadInt32()
Console.WriteLine(">>> dwLyricsLen ......... =
{0}",_end)
_ptr = pReader.ReadInt32()
Console.WriteLine(">>> pbLyrics ............ =
${0:X8}",_ptr)
_end = _end + _ptr
WHILE _ptr < _end
DIM line AS String
DIM time As Integer
line = Marshal.PtrToStringUni(NEW IntPtr(_ptr))
_ptr = _ptr + 2 * (1 + line.Length)
time = Marshal.ReadInt32(NEW IntPtr(_ptr))
_ptr = _ptr + 4
Console.WriteLine(">>>
[{0:d}:{1:d2}:{2:d2}.{3:d3}]
L""{4}""",time\1000\60\60,(time\1000\60) mod 60,(time\1000)
mod 60,time mod 1000,line)
END WHILE
ELSE IF szName = "WM/Picture" THEN
Console.WriteLine(">>> pwszMIMEType .. =
{0}",Marshal.PtrToStringUni(NEW
IntPtr(pReader.ReadInt32())))
Console.WriteLine(">>> bPictureType .. =
{0}",pReader.ReadByte())
Console.WriteLine(">>> pwszDescription =
L""{0}""",Marshal.PtrToStringUni(NEW
IntPtr(pReader.ReadInt32())))
_end = pReader.ReadInt32()
Console.WriteLine(">>> dwDataLen ..... = {0}",_end)
_ptr = pReader.ReadInt32()
Console.WriteLine(">>> pbData ........ =
${0:X8}",_ptr)
DIM pFile AS FileStream = NEW FileStream("picture" & i
& ".jpg",FileMode.OpenOrCreate,FileAccess.Write)
DIM bas AS IntPtr = NEW IntPtr(_ptr)
FOR off AS Integer = 0 TO _end-1
pFile.WriteByte(Marshal.ReadByte(bas,off))
NEXT off
END IF
NEXT i
DIM pLines() AS String = { "First Line", "Second Line" }
DIM pTimes() AS Integer = { 1500, 5230 }
DIM sz AS IntPtr = Marshal.StringToCoTaskMemUni("Some
string without meaning")
DIM cb AS Integer = 0
FOR i AS Integer = 0 TO pLines.Length-1
cb = cb + 4 + 2 * (1 + pLines(i).Length)
NEXT i
DIM pb AS IntPtr = Marshal.AllocCoTaskMem(cb)
DIM p AS Integer = 0
FOR i AS Integer = 0 TO pLines.Length-1
FOR k AS Integer = 0 TO pLines(i).Length-1
Marshal.WriteInt16(pb,p,Convert.ToInt16(pLines(i).Chars(k)))
p = p + 2
NEXT k
Marshal.WriteInt16(pb,p,Convert.ToInt16(0))
p = p + 2
Marshal.WriteInt32(pb,p,pTimes(i))
p = p + 4
NEXT i
DIM wIndex AS UInt16
DIM pData(14) AS Byte
DIM pBuffer AS MemoryStream = NEW MemoryStream(pData)
DIM pWriter AS BinaryWriter = NEW BinaryWriter(pBuffer)
pWriter.Write(Convert.ToByte(2))
pWriter.Write(Convert.ToByte(1))
pWriter.Write(sz.ToInt32())
pWriter.Write(Convert.ToUInt32(cb))
pWriter.Write(pb.ToInt32())
pHeader.AddAttribute(wStream,"WM/Lyrics_Synchronised",wIndex
,WMT_ATTR_DATATYPE.WMT_TYPE_BINARY,Convert.ToUInt16(0),pData
,Convert.ToUInt32(pData.Length))
pEditor.Flush()
Marshal.FreeCoTaskMem(pb)
Marshal.FreeCoTaskMem(sz)
CATCH ex AS COMException
Console.WriteLine(ex.ToString())
END TRY
END SUB
END MODULE
------------------------------------------
--
// Alessandro Angeli
// MVP :: Digital Media
// a dot angeli at psynet dot net
|
|
| Back to top |
|
 |
Alessandro Angeli [MVP::D
Guest
|
Posted:
Wed Oct 06, 2004 10:21 pm Post subject:
Re: About obscurity of some extended attributes structures d |
|
|
smith wrote:
| Quote: | I'm sure he did it just to be helpful, but when he
contacts me he'll get the token ;)
|
Why don't you donate the $10 to support UNICEF?
http://www.unicef.org/support/
Neil will buy me a beer next time I'm in Bristol instead :-)
--
// Alessandro Angeli
// MVP :: Digital Media
// a dot angeli at psynet dot net |
|
| Back to top |
|
 |
Vincas Stepankevicius
Guest
|
Posted:
Wed Oct 06, 2004 11:30 pm Post subject:
Re: About obscurity of some extended attributes structures d |
|
|
"Alessandro Angeli [MVP::DigitalMedia]" <nobody@nowhere.in.the.net> wrote in
message news:%23eEQDF9qEHA.3396@tk2msftngp13.phx.gbl...
| Quote: | smith wrote:
....
Neil will buy me a beer next time I'm in Bristol instead :-)
Good Lithuanian beer is waiting for you in Vilnius too :) |
-Vincas
|
|
| Back to top |
|
 |
Vincas Stepankevicius
Guest
|
Posted:
Thu Oct 07, 2004 1:47 am Post subject:
Re: About obscurity of some extended attributes structures d |
|
|
"Alessandro Angeli [MVP::DigitalMedia]" <nobody@nowhere.in.the.net> wrote in
message news:%233QvCF9qEHA.3396@tk2msftngp13.phx.gbl...
....
| Quote: | Added the code to add a new WM/Lyrics_Synchronised
attribute. There are more effient ways to do this: remember
you can copy whole array back and forth from managed arrays
and unmanaged memory buffers using the Marshal.Copy() family
of methods.
|
Great! I tested your sample - it works like a sharm (despite some minor, mp3
tagging rules related details wich are out of scope of our discussion).
The main thing is that thanks to your help WM attr updating is no longer any
problem for me (and I hope- not only for me).
Once more many thanks for your attitude, knowledge and wasted time,
-your debtor - Vincas |
|
| Back to top |
|
 |
Alessandro Angeli [MVP::D
Guest
|
Posted:
Thu Oct 07, 2004 2:18 am Post subject:
Re: About obscurity of some extended attributes structures d |
|
|
Vincas Stepankevicius wrote:
| Quote: | Once more many thanks for your attitude, knowledge and
wasted time, -your debtor - Vincas
|
You're welcome. I learned a few things myself in the
meantime (how to code using VB.NET for example, which I
never used before and I hope to never use again :-)).
--
// Alessandro Angeli
// MVP :: Digital Media
// a dot angeli at psynet dot net |
|
| Back to top |
|
 |
smith
Guest
|
Posted:
Thu Oct 07, 2004 2:40 am Post subject:
Re: About obscurity of some extended attributes structures d |
|
|
You're a saint, but let's just wrap this by the friendly rules, OK?. You
can donate it to whatever you want but don't make me feel bad, Alessandro,
send me an email :)
-smith
"Alessandro Angeli [MVP::DigitalMedia]" <nobody@nowhere.in.the.net> wrote in
message news:%23eEQDF9qEHA.3396@tk2msftngp13.phx.gbl...
| Quote: | smith wrote:
I'm sure he did it just to be helpful, but when he
contacts me he'll get the token ;)
Why don't you donate the $10 to support UNICEF?
http://www.unicef.org/support/
Neil will buy me a beer next time I'm in Bristol instead :-)
--
// Alessandro Angeli
// MVP :: Digital Media
// a dot angeli at psynet dot net
|
|
|
| Back to top |
|
 |
Neil Smith [MVP Digital M
Guest
|
Posted:
Fri Oct 08, 2004 3:26 am Post subject:
Re: About obscurity of some extended attributes structures d |
|
|
On Wed, 6 Oct 2004 20:21:08 +0200, "Alessandro Angeli
[MVP::DigitalMedia]" <nobody@nowhere.in.the.net> wrote:
| Quote: | smith wrote:
I'm sure he did it just to be helpful, but when he
contacts me he'll get the token ;)
Why don't you donate the $10 to support UNICEF?
http://www.unicef.org/support/
Neil will buy me a beer next time I'm in Bristol instead :-)
|
** He has a point - either there or at the next MVP summit hehe |
|
| Back to top |
|
 |
smith
Guest
|
Posted:
Fri Oct 08, 2004 8:56 pm Post subject:
Re: About obscurity of some extended attributes structures d |
|
|
to bed the contest: Alessandro has accepted the token prize so he can
afford your second round ... if it's Old Milwaukee, that is :)
"Neil Smith [MVP Digital Media]" <neil@nospam.com> wrote in message
news:72lbm0pv9utsjp9k0519258vtt1og4e0v5@4ax.com...
| Quote: | On Wed, 6 Oct 2004 20:21:08 +0200, "Alessandro Angeli
[MVP::DigitalMedia]" <nobody@nowhere.in.the.net> wrote:
snipp
** He has a point - either there or at the next MVP summit hehe |
|
|
| Back to top |
|
 |
Berdon
Joined: 16 Apr 2007
Posts: 1
|
Posted:
Mon Apr 16, 2007 7:04 am Post subject:
Re: About obscurity of some extended attributes structures d |
|
|
I realize that this post is 3+ years old. But I had to post anyway. Alessandro, my thanks, respect, and everything else I have to offer, go to you. This code has been what I've needed and searched for and I'm in your debt. (Specifically, I needed the code to grab the wm/picture)
Alessandro Angeli [MVP: wrote: | Vincas Stepankevicius wrote:
| Quote: | If I got it right, I can use your spelled e-mail for
sending such file. Correct me if I'm wrong.
|
Here is the sample code that dumps the synchronized lyrics:
---------------------------------------------
using System;
using System.IO;
using System.Runtime.InteropServices;
using WMFSDKWrapper;
public class slyr
{
public static void Main(string[] args)
{
try {
IWMMetadataEditor pEditor = null;
WMFSDKFunctions.WMCreateEditor(out pEditor);
pEditor.Open("x.wma");
IWMHeaderInfo3 pHeader = (IWMHeaderInfo3)pEditor;
ushort wStream = 0;
ushort wCount = 0;
pHeader.GetAttributeCountEx(wStream,out wCount);
for(ushort i = 0; i < wCount; i++) {
WMT_ATTR_DATATYPE dtType = 0;
ushort wLang = 0;
string szName = null;
byte[] pbData = null;
ushort wName = 0;
uint dwData = 0;
pHeader.GetAttributeByIndexEx(wStream,i,szName,ref
wName,out dtType,out wLang,pbData,ref dwData);
szName = new string('\0',wName-1);
pbData = new byte[dwData];
pHeader.GetAttributeByIndexEx(wStream,i,szName,ref
wName,out dtType,out wLang,pbData,ref dwData);
if(szName != "WM/Lyrics_Synchronised") continue;
MemoryStream pStream = new MemoryStream(pbData);
BinaryReader pReader = new BinaryReader(pStream);
uint ptr, end; string line; uint time;
Console.WriteLine(">>> bTimeStampFormat .... =
{0}",pReader.ReadByte());
Console.WriteLine(">>> bContentType ........ =
{0}",pReader.ReadByte());
Console.WriteLine(">>> pwszContentDescriptor =
L\"{0}\"",Marshal.PtrToStringUni(new
IntPtr(pReader.ReadUInt32())));
Console.WriteLine(">>> dwLyricsLen ......... = {0}",end
= pReader.ReadUInt32());
Console.WriteLine(">>> pbLyrics ............ =
${0:X8}",ptr = pReader.ReadUInt32());
for(end += ptr; ptr < end; ) {
line = Marshal.PtrToStringUni(new IntPtr(ptr)); ptr +=
(uint)(2*(1+line.Length));
time = (uint)Marshal.ReadInt32(new IntPtr(ptr)); ptr +=
4;
Console.WriteLine(">>>\t [{0:d}:{1:d2}:{2:d2}.{3:d3}]
L\"{4}\"",time/1000/60/60,(time/1000/60)%60,(time/1000)%60,t
ime%1000,line);
}
}
} catch(COMException ex) {
Console.WriteLine(ex.ToString());
}
}
}
---------------------------------------------
--
// Alessandro Angeli
// MVP :: Digital Media
// a dot angeli at psynet dot net |
|
|
| Back to top |
|
 |
|
|
|
|