我的设备甚至模拟器都没有声音。
实际上,在 "mMediaPlayer.create(this, musicIds[0]); " 行,eclipse 建议我有两个选择:"Change access to static using 'MediaPlayer'(declaring type)” 或 “在 Create() 上添加 @SuppressWarnings 'static-access'”。顺便说一句,我采纳了eclipse的建议........但还是不行。
附言我从其他项目 (pager) 调用了一个包。
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTitle(R.string.diff_title);
setContentView(R.layout.title_layout);
viewFlow = (ViewFlow) findViewById(R.id.viewflow);
DiffAdapter adapter = new DiffAdapter(this);
viewFlow.setAdapter(adapter);
TitleFlowIndicator indicator = (TitleFlowIndicator) findViewById(R.id.viewflowindic);
indicator.setTitleProvider(adapter);
viewFlow.setFlowIndicator(indicator);
//Set all views
listView = (ListView) findViewById(R.id.listView1);
listView.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, listeStrings));
final ImageView imv=(ImageView)findViewById(R.id.imv);
imv.setImageResource(imageIds[0]);
final ImageView pic = (ImageView)findViewById(R.id.Picture);
pic.setImageResource(imageIds[0]);
btnPlay = (ImageButton)findViewById(R.id.btnplay);
btnPlay.setOnClickListener(this);
btnNext = (ImageView)findViewById(R.id.imvnext);
btnLast = (ImageView)findViewById(R.id.imvlast);
final TextView textview = (TextView)findViewById(R.id.textView2);
textview.setText(listeStrings[0]);
seekBar = (SeekBar)findViewById(R.id.seekbar);
//seekBar.setMax(mMediaPlayer.getDuration());
mMediaPlayer.create(this, musicIds[0]);
try {
if (mMediaPlayer != null) {
mMediaPlayer.stop();
}
mMediaPlayer.prepare();
mMediaPlayer.start();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
listView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
int songIndex = position;
String songTitle=musicNames[position];
imv.setImageResource(imageIds[position]);
pic.setImageResource(imageIds[position]);
textview.setText(listeStrings[position]);
}
});
}
}
这是我的日志:
08-11 07:33:19.217: E/MediaPlayer(338): stop called in state 1
08-11 07:33:19.217: E/MediaPlayer(338): error (-38, 0)
08-11 07:33:19.217: E/MediaPlayer(338): prepareAsync called in state 0
08-11 07:33:19.217: W/System.err(338): java.lang.IllegalStateException
08-11 07:33:19.227: W/System.err(338): at android.media.MediaPlayer.prepare(Native Method)
08-11 07:33:19.227: W/System.err(338): at org.taptwo.android.widget.viewflow.example.DiffViewFlowExample.onCreate(DiffViewFlowExample.java:95)
08-11 07:33:19.227: W/System.err(338): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-11 07:33:19.227: W/System.err(338): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
08-11 07:33:19.227: W/System.err(338): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
08-11 07:33:19.227: W/System.err(338): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
08-11 07:33:19.227: W/System.err(338): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
08-11 07:33:19.227: W/System.err(338): at android.os.Handler.dispatchMessage(Handler.java:99)
08-11 07:33:19.227: W/System.err(338): at android.os.Looper.loop(Looper.java:123)
08-11 07:33:19.227: W/System.err(338): at android.app.ActivityThread.main(ActivityThread.java:3683)
08-11 07:33:19.227: W/System.err(338): at java.lang.reflect.Method.invokeNative(Native Method)
08-11 07:33:19.227: W/System.err(338): at java.lang.reflect.Method.invoke(Method.java:507)
08-11 07:33:19.227: W/System.err(338): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
08-11 07:33:19.227: W/System.err(338): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
08-11 07:33:19.227: W/System.err(338): at dalvik.system.NativeStart.main(Native Method)<br>
08-11 07:33:19.257: E/MediaPlayer(338): Error (-38,0)
最佳答案
在prepare()之前,您需要先调用setDataSource(..)。
媒体框架非常严格state machine ,处理所有不同的状态真的很麻烦。
我用过这个小 wrapper这使得编码/调试更容易一些。您可以尝试一下。
关于模拟器 - 请注意,并非所有文件格式都受支持。
关于Android MediaPlayer 问题 :"Error (-38 , 0) "和 "stop called in state 1",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11913108/
我正在尝试测试是否存在表单。我是Rails新手。我的new.html.erb_spec.rb文件的内容是:require'spec_helper'describe"messages/new.html.erb"doit"shouldrendertheform"dorender'/messages/new.html.erb'reponse.shouldhave_form_putting_to(@message)with_submit_buttonendendView本身,new.html.erb,有代码:当我运行rspec时,它失败了:1)messages/new.html.erbshou
我在从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""-
我正在使用这个:4.times{|i|assert_not_equal("content#{i+2}".constantize,object.first_content)}我之前声明过局部变量content1content2content3content4content5我得到的错误NameError:wrongconstantnamecontent2这个错误是什么意思?我很确定我想要content2=\ 最佳答案 你必须用一个大字母来调用ruby常量:Content2而不是content2。Aconstantnamestart
我想为Heroku构建一个Rails3应用程序。他们使用Postgres作为他们的数据库,所以我通过MacPorts安装了postgres9.0。现在我需要一个postgresgem并且共识是出于性能原因你想要pggem。但是我对我得到的错误感到非常困惑当我尝试在rvm下通过geminstall安装pg时。我已经非常明确地指定了所有postgres目录的位置可以找到但仍然无法完成安装:$envARCHFLAGS='-archx86_64'geminstallpg--\--with-pg-config=/opt/local/var/db/postgresql90/defaultdb/po
尝试通过RVM将RubyGems升级到版本1.8.10并出现此错误:$rvmrubygemslatestRemovingoldRubygemsfiles...Installingrubygems-1.8.10forruby-1.9.2-p180...ERROR:Errorrunning'GEM_PATH="/Users/foo/.rvm/gems/ruby-1.9.2-p180:/Users/foo/.rvm/gems/ruby-1.9.2-p180@global:/Users/foo/.rvm/gems/ruby-1.9.2-p180:/Users/foo/.rvm/gems/rub
为了将Cucumber用于命令行脚本,我按照提供的说明安装了arubagem。它在我的Gemfile中,我可以验证是否安装了正确的版本并且我已经包含了require'aruba/cucumber'在'features/env.rb'中为了确保它能正常工作,我写了以下场景:@announceScenario:Testingcucumber/arubaGivenablankslateThentheoutputfrom"ls-la"shouldcontain"drw"假设事情应该失败。它确实失败了,但失败的原因是错误的:@announceScenario:Testingcucumber/ar
我的最终目标是安装当前版本的RubyonRails。我在OSXMountainLion上运行。到目前为止,这是我的过程:已安装的RVM$\curl-Lhttps://get.rvm.io|bash-sstable检查已知(我假设已批准)安装$rvmlistknown我看到当前的稳定版本可用[ruby-]2.0.0[-p247]输入命令安装$rvminstall2.0.0-p247注意:我也试过这些安装命令$rvminstallruby-2.0.0-p247$rvminstallruby=2.0.0-p247我很快就无处可去了。结果:$rvminstall2.0.0-p247Search
由于fast-stemmer的问题,我很难安装我想要的任何rubygem。我把我得到的错误放在下面。Buildingnativeextensions.Thiscouldtakeawhile...ERROR:Errorinstallingfast-stemmer:ERROR:Failedtobuildgemnativeextension./System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/rubyextconf.rbcreatingMakefilemake"DESTDIR="cleanmake"DESTDIR=
我遵循MichaelHartl的“RubyonRails教程:学习Web开发”,并创建了检查用户名和电子邮件长度有效性的测试(名称最多50个字符,电子邮件最多255个字符)。test/helpers/application_helper_test.rb的内容是:require'test_helper'classApplicationHelperTest在运行bundleexecraketest时,所有测试都通过了,但我看到以下消息在最后被标记为错误:ERROR["test_full_title_helper",ApplicationHelperTest,1.820016791]test
我正在尝试从Postgresql表(table1)中获取数据,该表由另一个相关表(property)的字段(table2)过滤。在纯SQL中,我会这样编写查询:SELECT*FROMtable1JOINtable2USING(table2_id)WHEREtable2.propertyLIKE'query%'这工作正常:scope:my_scope,->(query){includes(:table2).where("table2.property":query)}但我真正需要的是使用LIKE运算符进行过滤,而不是严格相等。然而,这是行不通的:scope:my_scope,->(que