啊
mp3 frame header
AAAAAAAA AAABBCCD EEEEFFGH IIJJKLMM
| Sign | Length (bits) |
Position (bits) |
Description | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| A | 11 | (31-21) | Frame sync (all bits must be set) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| B | 2 | (20,19) | MPEG Audio version ID 00 – MPEG Version 2.5 (later extension of MPEG 2) 01 – reserved 10 – MPEG Version 2 (ISO/IEC 13818-3) 11 – MPEG Version 1 (ISO/IEC 11172-3) Note: MPEG Version 2.5 was added lately to the MPEG 2 standard. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| C | 2 | (18,17) | Layer description 00 – reserved 01 – Layer III 10 – Layer II 11 – Layer I |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| D | 1 | (16) | Protection bit 0 – Protected by CRC (16bit CRC follows header) 1 – Not protected |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| E | 4 | (15,12) | Bitrate index
NOTES: All values are in kbps “free” means free format. The free bitrate must MPEG files may feature variable bitrate (VBR). Each frame For Layer II there are some combinations of bitrate and mode
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| F | 2 | (11,10) | Sampling rate frequency index
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| G | 1 | (9) | Padding bit 0 – frame is not padded 1 – frame is padded with one extra slot Padding is used to exactly fit the bitrate.As an example: 128kbps |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| H | 1 | (8) | Private bit. This one is only informative. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| I | 2 | (7,6) | Channel Mode 00 – Stereo 01 – Joint stereo (Stereo) 10 – Dual channel (2 mono channels) 11 – Single channel (Mono) Note: Dual channel files are made of two independant mono channel. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| J | 2 | (5,4) | Mode extension (Only used in Joint stereo)
Mode extension is used to join informations that are of no Complete frequency range of MPEG file is divided in subbands
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| K | 1 | (3) | Copyright 0 – Audio is not copyrighted 1 – Audio is copyrighted The copyright has the same meaning as the copyright bit on CDs |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| L | 1 | (2) | Original 0 – Copy of original media 1 – Original media The original bit indicates, if it is set, that the frame is |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| M | 2 | (1,0) | Emphasis 00 – none 01 – 50/15 ms 10 – reserved 11 – CCIT J.17 The emphasis indication is here to tell the decoder that the |
C#中实现单实例
public class SingletonDemo
{
private static SingletonDemo theSingleton = null;
private SingletonDemo() { }
public static SingletonDemo Instance()
{
if (theSingleton == null)
{
theSingleton = new SingletonDemo();
}
return theSingleton;
}
static void Main(string[] args)
{
SingletonDemo s1 = SingletonDemo.Instance();
SingletonDemo s2 = SingletonDemo.Instance();
if (s1.Equals(s2))
{
Console.WriteLine("see, only one instance!");
}
}
}
更改flash builder 语言
安装目录里有个FlashBuilder.ini
打开
-clean
-nl
en_US
-startup
plugins/org.eclipse.equinox.launcher_1.0.201.R35x_v20090715.jar
--launcher.library
plugins/org.eclipse.equinox.launcher.win32.win32.x86_1.0.200.v20090519
-vmargs
-Xms256m
-Xmx512m
-XX:MaxPermSize=256m
-XX:PermSize=64m
-Djava.net.preferIPv4Stack=true
-Dorg.eclipse.equinox.p2.resolve
第三行是语言
可用的有:
de_DE
fr_FR
ja_JP
ru_RU
zh_CN
en_US
ActionScript访问WCF的svc WebService读取二进制数据
先写个wcf的svc服务
有个方法叫TestImage,返回一个图片的二进制数据
写好服务能用之后开始ActionScript的实现
先在build path里加入fiber.swc
我的fiber.swc路径是C:Program FilesAdobeAdobe Flash Builder 4pluginscom.adobe.flexbuilder.dcrad_4.0.0.272416dcradSwcs4.0libsfiber.swc
然后是代码
package WebService
{
import com.adobe.fiber.core.model_internal;
import com.adobe.fiber.services.wrapper.WebServiceWrapper;
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.filesystem.File;
import flash.filesystem.FileMode;
import flash.filesystem.FileStream;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.net.URLRequestMethod;
import flash.net.URLVariables;
import flash.utils.ByteArray;
import mx.rpc.AbstractOperation;
import mx.rpc.AsyncToken;
import mx.rpc.events.ResultEvent;
import mx.rpc.soap.mxml.WebService;
public class ImageTest extends WebServiceWrapper
{
public function ImageTest()
{
_serviceControl = new WebService();
//load wsdl
_serviceControl.loadWSDL("http://192.168.0.2:8080/EpubService/Service1.svc?wsdl");
model_internal::initialize();
getImage();
}
public function getImage():void
{
var operation:AbstractOperation = _serviceControl.getOperation("TestImage");
operation.addEventListener(ResultEvent.RESULT,onresult);
operation.send();
}
private function onresult(e:ResultEvent):void
{
var imgByte:ByteArray = e.result as ByteArray;
var f:File = File.documentsDirectory.resolvePath("test.jpg");
var fs:FileStream = new FileStream();
try
{
//open file in write mode
fs.open(f,FileMode.WRITE);
//write bytes from the byte array
fs.writeBytes(imgByte);
trace("create file: "+f.nativePath);
}
catch(e:Error)
{
trace(e.message);
}
finally
{
//close the file
fs.close();
}
}
}
}
输出:
create file: C:UsersQingDocumentstest.jpg
Air中mx.controls.HTML使用htmlText加载图片
html.htmlLoader.placeLoadStringContentInApplicationSandbox = true;
android写Xml文件
废话少说,直接看代码
package cn.qing.xmltest;
import java.io.*;
import org.xmlpull.v1.XmlSerializer;
import android.app.Activity;
import android.os.*;
import android.util.*;
import android.widget.TextView;
public class wrXml extends Activity {
/** Called when the activity is first created. */
private String appDir;
private String xmlFileName;
StringBuilder sb;
TextView tv;
public wrXml(){
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
appDir = this.getApplicationContext().getFilesDir().getAbsolutePath();
xmlFileName = appDir + "/test.xml";
tv = new TextView(this);
sb = new StringBuilder();
writeXml();
tv.setText(sb.toString());
setContentView(tv);
}
private void writeXml() {
File xmlFile = new File(xmlFileName);
try {
xmlFile.createNewFile();
} catch (IOException e) {
Log.e("IOException", "exception in createNewFile() method");
}
FileOutputStream fileos = null;
try {
fileos = new FileOutputStream(xmlFile);
} catch (FileNotFoundException e) {
Log.e("FileNotFoundException", "can't create FileOutputStream");
}
XmlSerializer serializer = Xml.newSerializer();
try {
serializer.setOutput(fileos, "UTF-8");
serializer.startDocument(null, Boolean.valueOf(true));
serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output",true);
serializer.startTag(null, "root");
serializer.startTag(null, "child1");
serializer.endTag(null, "child1");
serializer.startTag(null, "child2");
serializer.attribute(null, "attribute", "value");
serializer.endTag(null, "child2");
serializer.startTag(null, "child3");
serializer.text("some text inside child3");
serializer.endTag(null, "child3");
serializer.endTag(null, "root");
serializer.endDocument();
serializer.flush();
fileos.close();
sb.append("file has been created");
} catch (Exception e) {
Log.e("Exception", "error occurred while creating xml file");
sb.append("Create file error");
}
}
}
.net mvc 中使用ActionFilterAttribute过滤器
过滤器是mvc中常用的
在.net mvc 中直接继承和实现ActionFilterAttribute类就可以了
很简单
下面贴出一个例子
过滤器:
public class UseStopwatchAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
filterContext.Controller.ViewData["stopWatch"] = stopWatch;
}
public override void OnResultExecuting(ResultExecutingContext filterContext)
{
Stopwatch stopWatch = (Stopwatch)filterContext.Controller.ViewData["stopWatch"];
stopWatch.Stop();
Random r = new Random();
filterContext.Controller.ViewData["elapsedTime"] = stopWatch.ElapsedMilliseconds
+ " milliseconds - Rand " + r.Next(1000).ToString();
}
}
这的话这个过滤器就写好了
在使用的时候只要在controller上写上就行了
[UseStopwatch]
public class ProductsController : Controller
{
//
// GET: /Store/Products/
public ActionResult List()
{
return View();
}
public ActionResult Details()
{
return View();
}
public ActionResult AddReview()
{
return View();
}
}
C#中同步、异步读取进程输出信息
1、异步的:
p.StartInfo.RedirectStandardError = true;
p.ErrorDataReceived += new DataReceivedEventHandler(OutputInfo);
p.Start();
p.BeginErrorReadLine();
private void OutputInfo(object sendProcess, DataReceivedEventArgs output){
if (!String.IsNullOrEmpty(output.Data))
{
//处理方法...
}
}
2、同步的
p.StartInfo.RedirectStandardError = true;
p.Start();
StreamReader sr = ffmpeg.StandardError;
p.WaitForExit();//之后就可以从sr里读了
C#中枚举类型enum的使用
1、关于enum的定义
enum Fabric
{
Cotton = 1,
Silk = 2,
Wool = 4,
Rayon = 8,
Other = 128
}
2、符号名和常数值的互相转换
Fabric fab = Fabric.Cotton;
int fabNum = (int)fab;//转换为常数值。必须使用强制转换。
Fabric fabString = (Fabric)1;//常数值转换成符号名。如果使用ToString(),则是((Fabric)1).ToString(),注意必须有括号。
string fabType = fab.ToString();//显示符号名
string fabVal = fab.ToString ("D");//显示常数值
3、获得所有符号名的方法(具体参见Enum类)
public enum MyFamily
{
YANGZHIPING = 1,
GUANGUIQIN = 2,
YANGHAORAN = 4,
LIWEI = 8,
GUANGUIZHI = 16,
LISIWEN = 32,
LISIHUA = 64,
}
foreach (string s in Enum.GetNames(typeof(MyFamily)))
{
Console.WriteLine(s);
}
4、将枚举作为位标志来处理
根据下面的两个例子,粗略地说,一方面,设置标志[Flags]或者[FlagsAttribute],则表明要将符号名列举出来;另一方面,可以通过强制转换,将数字转换为符号名。说不准确。看下面的例子体会吧。注意:
- 例一:
Fabric fab = Fabric.Cotton | Fabric.Rayon | Fabric.Silk;
Console.WriteLine("MyFabric = {0}", fab);//输出:Fabric.Cotton | Fabric.Rayon | Fabric.Silk;
- 例二:
class FlagsAttributeDemo
{
// Define an Enum without FlagsAttribute.
enum SingleHue : short
{
Black = 0,
Red = 1,
Green = 2,
Blue = 4
};
// Define an Enum with FlagsAttribute.
[FlagsAttribute]
enum MultiHue : short
{
Black = 0,
Red = 1,
Green = 2,
Blue = 4
};
static void Main( )
{
Console.WriteLine(
"This example of the FlagsAttribute attribute n" +
"generates the following output." );
Console.WriteLine(
"nAll possible combinations of values of an n" +
"Enum without FlagsAttribute:n" );
// Display all possible combinations of values.
for( int val = 0; val <= 8; val++ )
Console.WriteLine( "{0,3} – {1}", val, ( (SingleHue)val ).ToString( ) );
Console.WriteLine( "nAll possible combinations of values of an n" + "Enum with FlagsAttribute:n" );
// Display all possible combinations of values.
// Also display an invalid value.
for( int val = 0; val <= 8; val++ )
Console.WriteLine ( "{0,3} – {1}", val, ( (MultiHue)val ).ToString( ) );
}
}
/*
This example of the FlagsAttribute attribute
generates the following output.
All possible combinations of values of an
Enum without FlagsAttribute:
0 – Black
1 – Red
2 – Green
3 – 3
4 – Blue
5 – 5
6 – 6
7 – 7
8 – 8
All possible combinations of values of an
Enum with FlagsAttribute:
0 – Black
1 – Red
2 – Green
3 – Red, Green
4 – Blue
5 – Red, Blue
6 – Green, Blue
7 – Red, Green, Blue
8 – 8
*/
5、枚举作为函数参数。经常和switch结合起来使用。下面举例
public static double GetPrice(Fabric fab)
{
switch (fab)
{
case Fabric.Cotton:
return (3.55);
case Fabric.Silk:
return (5.65);
case Fabric.Wool:
return (4.05);
case Fabric.Rayon:
return (3.20);
case Fabric.Other:
return (2.50);
default:
return (0.0);
}
}
6、上面三点一个完整的例子
//enum的定义
public enum Fabric : short
{
Cotton = 1,
Silk = 2,
Wool = 3,
Rayon = 8,
Other = 128
}
//将枚举作为参数传递
public static double GetPrice(Fabric fab)
{
switch (fab)
{
case Fabric.Cotton: return (3.55);
case Fabric.Silk : return (5.65);
case Fabric.Wool: return (4.05);
case Fabric.Rayon: return (3.20);
case Fabric.Other: return (2.50);
default: return (0.0);
}
}
public static void Main()
{
Fabric fab = Fabric.Cotton;
int fabNum = (int)fab;
string fabType = fab.ToString();
string fabVal = fab.ToString ("D");
double cost = GetPrice(fab);
Console.WriteLine("fabNum = {0}nfabType = {1}nfabVal = {2}n", fabNum, fabType, fabVal);
Console.WriteLine("cost = {0}", cost);
}
7、Enum类的使用
Enum.IsDefinde、Enum.Parse两种方法经常一起使用,来确定一个值或符号是否是一个枚举的成员,然后创建一个实例。Enum.GetName打印出一个成员的值;Enum.GetNames打印出所有成员的值。其中注意**“`typeof“`**的使用。这一点很重要。
public enum MyFamily
{
YANGZHIPING = 1,
GUANGUIQIN = 2,
YANGHAORAN = 4,
LIWEI = 8,
GUANGUIZHI = 16,
LISIWEN = 32,
LISIHUA = 64,
}
string s = "YANGHAORAN";
if (Enum.IsDefined(typeof(MyFamily), s))
{
MyFamily f = (MyFamily)Enum.Parse(typeof(MyFamily), s);
GetMyFamily(f);
Console.WriteLine("The name is:" + Enum. GetName(typeof(MyFamily), 2));
string[] sa = Enum.GetNames(typeof(MyFamily));
foreach (string ss in sa)
{
Console.WriteLine(ss);
}
}