내 앱에 배경 음악을 추가하려고합니다. 많은 예제를 읽었지만 항상 같은 문제가 있습니다. 음악이 시작되지 않고 오류 메시지가 없습니다.내 앱의 배경 음악이 시작되지 않습니다.
나는 배경 음악을 menages 클래스가
import android.app.Service;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.IBinder;
public class BackgroundSoundService extends Service {
private static final String TAG = null;
MediaPlayer player;
public IBinder onBind(Intent arg0) {
return null;
}
@Override
public void onCreate() {
super.onCreate();
player = MediaPlayer.create(this, R.raw.jingle);
player.setLooping(true); // Set looping
player.setVolume(100,100);
player.start();
}
@Override
public void onStart(Intent intent, int startId) {
super.onStart(intent, startId);
}
public void onDestroy() {
super.onDestroy();
}
protected void onNewIntent() {
player.pause();
}
}
그리고, 내 메인 클래스에서에서 onCreate 메서드 내, 나는이 내 매니페스트
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.giocobambini"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="16" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.giocobambini.MainActivity"
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="com.example.giocobambini.BackgroundSoundService"
android:label="@string/title_activity_background_sound_service" >
</activity>
</application>
</manifest>
Intent svc=new Intent(this, BackgroundSoundService.class);
startService(svc);
이다 사용
아마도 문제는 minSdkVersion = "8"입니다! MinSdkVersion 8에 대한 배경 음악이 지원되지 않을 수 있습니까?
'player.prepare();'를 추가하기 전에. –
아니, 아직 시작되지 않습니다 :( – MDP
나는 BackgroundSoundService 클래스를 호출 할 수 있다고 생각합니다. 을 BackgroundSoundService 클래스의에서 onCreate 메서드에서, 나는 텍스트 뷰에서 뭔가를 작성했습니다.하지만 could't이 있음을 의미 내 주요 클래스에서 나는 BackgroundSoundService 클래스를 호출 할 수 아니에요! – MDP