<分区> 分区>
import java.io.BufferedReader;
public class Main extends Activity implements SurfaceHolder.Callback,
MediaPlayer.OnCompletionListener, View.OnClickListener, OnInitListener {
String SrcPath = "";
MediaPlayer mp;
SurfaceView mSurfaceView;
private SurfaceHolder holderrrr;
Boolean play = false;
String t_alarm1 = "alarm.xml", t_alarm2 = "alarm2.xml", text;
// TextToSpeach
private TextToSpeech mText2Speech;
@Override
protected void onCreate(Bundle savedInstanceState) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
.permitAll().build();
StrictMode.setThreadPolicy(policy);
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
addListenerOnButton();
mText2Speech = new TextToSpeech(Main.this, Main.this);
}
// menü
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_settings: {
Intent myIntent = new Intent(this, menu.class);
Main.this.startActivity(myIntent);
return true;
}
}
return true;
}
// kilépésfigyelő
private static final long DOUBLE_PRESS_INTERVAL = 2000000000;// 2 másodperc
private long lastPressTime;
@Override
public void onBackPressed() {
Toast.makeText(Main.this, getString(R.string.kilepes_dupla),
Toast.LENGTH_SHORT).show();
long pressTime = System.nanoTime();
if (pressTime - lastPressTime <= DOUBLE_PRESS_INTERVAL) {
// this is a double click event
System.exit(0);
}
lastPressTime = pressTime;
}
public void onInit(int status) {
if (status == TextToSpeech.SUCCESS) {
mText2Speech.setLanguage(Locale.getDefault()); // alaértelmezett
// nyelv a TtS-hez
}
}
private void addListenerOnButton() {
final Button button5 = (Button) findViewById(R.id.button5);
button5.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Perform action on click
if (play) {
try{
mp.stop();
mp.release();
mp = null;
}catch(Exception e){
}
button5.setText("Start");
play = false;
} else {
try {
mp = new MediaPlayer();
mSurfaceView = (SurfaceView) findViewById(R.id.surface);
holderrrr = mSurfaceView.getHolder();
play = true;
button5.setText("Stop");
surfaceCreated(holderrrr);
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
});
}// addlistener vége
public void surfaceCreated(SurfaceHolder holder) {
mp.setDisplay(holder);
holder = mSurfaceView.getHolder();
holder.addCallback(this);
holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
try {
mp.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
mp.stop();
mp.release();
Toast.makeText(Main.this,
"A videó lejátszás befejeződött!",
Toast.LENGTH_SHORT).show();
// button5.setText("Start");
//play = false;
}
});
mp.setDataSource(SrcPath);
mp.prepare();
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// Get the dimensions of the video
// int videoWidth = mp.getVideoWidth();
// int videoHeight = mp.getVideoHeight();
// Get the width of the screen
// int screenWidth = getWindowManager().getDefaultDisplay().getWidth();
// Get the SurfaceView layout parameters
android.view.ViewGroup.LayoutParams lp = mSurfaceView.getLayoutParams();
// Set the width of the SurfaceView to the width of the screen
// lp.width = screenWidth;
lp.width = 420;
// Set the height of the SurfaceView to match the aspect ratio of the
// video
// be sure to cast these as floats otherwise the calculation will likely
// be 0
// lp.height = (int) (((float) videoHeight / (float) videoWidth) *
// (float) screenWidth);
lp.height = 390;
// Commit the layout parameters
mSurfaceView.setLayoutParams(lp);
// Start video
mp.start();
}
}
}
它在 galaxy s3 上的 4.1.2 android 上工作正常,但它给了我标题中的错误消息。而且它不显示前 3 秒的视频... 请给我一些建议或一些解决方案,因为我不知道如何摆脱这种错误
我需要在客户计算机上运行Ruby应用程序。通常需要几天才能完成(复制大备份文件)。问题是如果启用sleep,它会中断应用程序。否则,计算机将持续运行数周,直到我下次访问为止。有什么方法可以防止执行期间休眠并让Windows在执行后休眠吗?欢迎任何疯狂的想法;-) 最佳答案 Here建议使用SetThreadExecutionStateWinAPI函数,使应用程序能够通知系统它正在使用中,从而防止系统在应用程序运行时进入休眠状态或关闭显示。像这样的东西:require'Win32API'ES_AWAYMODE_REQUIRED=0x0
我在从html页面生成PDF时遇到问题。我正在使用PDFkit。在安装它的过程中,我注意到我需要wkhtmltopdf。所以我也安装了它。我做了PDFkit的文档所说的一切......现在我在尝试加载PDF时遇到了这个错误。这里是错误:commandfailed:"/usr/local/bin/wkhtmltopdf""--margin-right""0.75in""--page-size""Letter""--margin-top""0.75in""--margin-bottom""0.75in""--encoding""UTF-8""--margin-left""0.75in""-
我在我的项目目录中完成了compasscreate.和compassinitrails。几个问题:我已将我的.sass文件放在public/stylesheets中。这是放置它们的正确位置吗?当我运行compasswatch时,它不会自动编译这些.sass文件。我必须手动指定文件:compasswatchpublic/stylesheets/myfile.sass等。如何让它自动运行?文件ie.css、print.css和screen.css已放在stylesheets/compiled。如何在编译后不让它们重新出现的情况下删除它们?我自己编译的.sass文件编译成compiled/t
大约一年前,我决定确保每个包含非唯一文本的Flash通知都将从模块中的方法中获取文本。我这样做的最初原因是为了避免一遍又一遍地输入相同的字符串。如果我想更改措辞,我可以在一个地方轻松完成,而且一遍又一遍地重复同一件事而出现拼写错误的可能性也会降低。我最终得到的是这样的:moduleMessagesdefformat_error_messages(errors)errors.map{|attribute,message|"Error:#{attribute.to_s.titleize}#{message}."}enddeferror_message_could_not_find(obje
Rackup通过Rack的默认处理程序成功运行任何Rack应用程序。例如:classRackAppdefcall(environment)['200',{'Content-Type'=>'text/html'},["Helloworld"]]endendrunRackApp.new但是当最后一行更改为使用Rack的内置CGI处理程序时,rackup给出“NoMethodErrorat/undefinedmethod`call'fornil:NilClass”:Rack::Handler::CGI.runRackApp.newRack的其他内置处理程序也提出了同样的反对意见。例如Rack
我想用ruby编写一个小的命令行实用程序并将其作为gem分发。我知道安装后,Guard、Sass和Thor等某些gem可以从命令行自行运行。为了让gem像二进制文件一样可用,我需要在我的gemspec中指定什么。 最佳答案 Gem::Specification.newdo|s|...s.executable='name_of_executable'...endhttp://docs.rubygems.org/read/chapter/20 关于ruby-在Ruby中编写命令行实用程序
我构建了两个需要相互通信和发送文件的Rails应用程序。例如,一个Rails应用程序会发送请求以查看其他应用程序数据库中的表。然后另一个应用程序将呈现该表的json并将其发回。我还希望一个应用程序将存储在其公共(public)目录中的文本文件发送到另一个应用程序的公共(public)目录。我从来没有做过这样的事情,所以我什至不知道从哪里开始。任何帮助,将不胜感激。谢谢! 最佳答案 无论Rails是什么,几乎所有Web应用程序都有您的要求,大多数现代Web应用程序都需要相互通信。但是有一个小小的理解需要你坚持下去,网站不应直接访问彼此
我尝试运行2.x应用程序。我使用rvm并为此应用程序设置其他版本的ruby:$rvmuseree-1.8.7-head我尝试运行服务器,然后出现很多错误:$script/serverNOTE:Gem.source_indexisdeprecated,useSpecification.Itwillberemovedonorafter2011-11-01.Gem.source_indexcalledfrom/Users/serg/rails_projects_terminal/work_proj/spohelp/config/../vendor/rails/railties/lib/r
刚入门rails,开始慢慢理解。有人可以解释或给我一些关于在application_controller中编码的好处或时间和原因的想法吗?有哪些用例。您如何为Rails应用程序使用应用程序Controller?我不想在那里放太多代码,因为据我了解,每个请求都会调用此Controller。这是真的? 最佳答案 ApplicationController实际上是您应用程序中的每个其他Controller都将从中继承的类(尽管这不是强制性的)。我同意不要用太多代码弄乱它并保持干净整洁的态度,尽管在某些情况下ApplicationContr
我花了三天的时间用头撞墙,试图弄清楚为什么简单的“rake”不能通过我的规范文件。如果您遇到这种情况:任何文件夹路径中都不要有空格!。严重地。事实上,从现在开始,您命名的任何内容都没有空格。这是我的控制台输出:(在/Users/*****/Desktop/LearningRuby/learn_ruby)$rake/Users/*******/Desktop/LearningRuby/learn_ruby/00_hello/hello_spec.rb:116:in`require':cannotloadsuchfile--hello(LoadError) 最佳