delphi xe7 android 程序出错
unit Unit3;interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Layouts,
FMX.ListBox, FMX.Controls.Presentation, FMX.Edit, FMX.StdCtrls, FMX.Ani,
FMX.Objects, FMX.DateTimeCtrls, FMX.Media,
Androidapi.JNI.App,Androidapi.JNIBridge,Androidapi.JNI.Os,Androidapi.Helpers,
Androidapi.JNI.Media;
type
TForm3 = class(TForm)
Button1: TButton;
Edit1: TEdit;
ListBox1: TListBox;
Button2: TButton;
ColorKeyAnimation1: TColorKeyAnimation;
Hz: TLabel;
Button3: TButton;
Button4: TButton;
procedure Button1Click(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
private
{ Private declarations }
I:Integer;
frequency1:Integer;
at1:JAudioTrack;
soundData: array of Byte;//Shortint;
public
{ Public declarations }
end;
var
Form3: TForm3;
implementation
{$R *.fmx}
procedure TForm3.Button1Click(Sender: TObject);
begin
ListBox1.Items.Add(Edit1.Text+'('+IntToStr(I)+')!');
I:=I+1;
end;
procedure TForm3.Button2Click(Sender: TObject);
begin
Application.Terminate;
end;
procedure TForm3.Button3Click(Sender: TObject);
var
LVibrator: JVibrator;
begin
LVibrator := TJVibrator.Wrap
((SharedActivity.getSystemService(TJActivity.JavaClass.VIBRATOR_SERVICE)
as ILocalObject).GetObjectID); // 调用振动
if not LVibrator.hasVibrator then
begin
ShowMessage('手机不支持震动');
Exit;
end;
LVibrator.vibrate(500); // 振动500毫秒
end;
procedure TForm3.Button4Click(Sender: TObject);
var
outF,buff_write:Integer;
chalconfig:Integer;
audioEncoding:Integer;
playBufferSize:Integer;
i,b:Integer;
a,s2,s3:Double;
//pk:Pointer;
begin
outF:=44100;
chalconfig:= TJAudioFormat.JavaClass.CHANNEL_OUT_MONO;
audioEncoding:=TJAudioFormat.JavaClass.ENCODING_PCM_8BIT;
playBufferSize:= TJAudioTrack.JavaClass.getMinBufferSize(outF, chalconfig, audioEncoding);
playBufferSize:=playBufferSize*2;
at1:= TJAudioTrack.JavaClass.init(TJAudioManager.JavaClass.STREAM_MUSIC,outF,
chalconfig,audioEncoding,playBufferSize,
TJAudioTrack.JavaClass.MODE_STREAM);
i:=0;
a:=frequency1/(outF*2*3.1415926);
SetLength (soundData, playBufferSize);
for i := 0 to playBufferSize do
begin
s3:=128*sin(a*i);
b:=round(s3);
soundData[i]:=Byte(b);
//i:=i+1;
end;
at1.play;
at1.write(soundData,0,playBufferSize);//这里通不过
end;
procedure TForm3.FormShow(Sender: TObject);
begin
I:=0;
frequency1:=1000;
end;
end.