簡體   English   中英

聲音無法播放 android

[英]Sounds won't play android

好吧,我知道我在接受率方面並不是最好的……我會彌補這一點……話雖這么說。

我遵循了大量的啟動畫面教程,並認為我有一些可以工作的東西......但是,聲音不起作用......每當我完成時,我都會收到錯誤“無法解決或不是一個領域”

任何建議:這里是完整的 SplashScreen.java 代碼:

 package com.droidnova.android;

 import android.app.Activity;
 import android.content.Intent;
 import android.media.MediaPlayer;
 import android.os.Bundle;
 import android.view.MotionEvent;
 import android.R;


 public class SplashScreen extends Activity {
protected boolean _active = true;
protected int _splashTime = 5000;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splash);

    MediaPlayer mpSplash = MediaPlayer.create(this, R.raw.laugh);
    mpSplash.start();

    // thread for displaying the SplashScreen
    Thread splashTread = new Thread() {
        @Override
        public void run() {
            try {
                int waited = 0;
                while(_active && (waited < _splashTime)) {
                    sleep(100);
                    if(_active) {
                        waited += 100;
                    }
                }
            } catch(InterruptedException e) {
                // do nothing
            } finally {
                finish();
                startActivity(new Intent("com.droidnova.android.splashscreen.MyApp"));
                stop();
            }
        }
    };
    splashTread.start();
}

@Override
public boolean onTouchEvent(MotionEvent event) {
    if (event.getAction() == MotionEvent.ACTION_DOWN) {
        _active = false;
    }
    return true;
     }
}

有什么建議么?

更新!

這是 AndroidManifest.xml 影片的代碼:

 <?xml version="1.0" encoding="utf-8"?>
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.droidnova.android"
  android:versionCode="1"
  android:versionName="1.0">
 <application android:icon="@drawable/icon" android:label="@string/app_name">
    <activity android:name=".SplashScreen"
              android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".MyApp">
        <intent-filter>
            <action android:name="com.droidnova.android.splashscreen.MyApp" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
 </application>
 <uses-sdk android:minSdkVersion="4" />
 </manifest>

第 5 行和第 6 行有錯誤:
第 5 行: error: Error: No resource found that matches the given name (at 'label' with value '@string/ app_name').
第 6 行: error: Error: No resource found that matches the given name (at 'label' with value '@string/ app_name').

添加了 R.java:

 /* AUTO-GENERATED FILE.  DO NOT MODIFY.
  *
  * This class was automatically generated by the
  * aapt tool from the resource data it found.  It
  * should not be modified by hand.
  */

 package com.droidnova.android;

 public final class R {
     public static final class attr {
}
public static final class drawable {
    public static final int icon=0x7f020000;
}
public static final class id {
    public static final int textView1=0x7f050000;
}
public static final class layout {
    public static final int main=0x7f030000;
    public static final int splash=0x7f030001;
}
public static final class string {
    public static final int app_name=0x7f040000;
    public static final int main_screen=0x7f040001;
    public static final int splash_screen=0x7f040002;
}
}

嘗試刪除import android.R; .

確保res/raw文件夾中有一個名為“laugh”的文件。

You should go ahead and include the actual build errors, but I suspect that you changed the class package but not the package name in the AndroidManifest.xml file. AndroidManifest.xml 文件中的 package 名稱是什么?

EDIT: that package name should be exactly the same as the class package ( com.droidnova.android ) or you'll get build-time resolution errors.

Assuming you have automatic building on in Eclipse, and deleting R.java and rebuilding didn't fix your problem, one thing I can think of causing this issue would be if you tried to run the app while an XML document was open. 檢查資源中是否有任何額外的*.out.xml文件(例如main.out.xml )。 如果您發現其中任何一個,請刪除它們,清理您的項目(Project > Clean...),看看這是否能解決問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM