Note that there are some explanatory texts on larger screens.

plurals
  1. POBackground music in my app doesn't start
    primarykey
    data
    text
    <p>I'm trying to add background music to my app. I read a lot of examples, but I have always the same problem. The music doesn't start, and I have no error message.</p> <p>I have a class that menages the background music</p> <pre><code>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(); } } </code></pre> <p>And, in my main class, inside the onCreate method, I use </p> <pre><code> Intent svc=new Intent(this, BackgroundSoundService.class); startService(svc); </code></pre> <p>This is my manifest</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.giocobambini" android:versionCode="1" android:versionName="1.0" &gt; &lt;uses-sdk android:minSdkVersion="8" android:targetSdkVersion="16" /&gt; &lt;application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" &gt; &lt;activity android:name="com.example.giocobambini.MainActivity" android:label="@string/app_name" &gt; &lt;intent-filter&gt; &lt;action android:name="android.intent.action.MAIN" /&gt; &lt;category android:name="android.intent.category.LAUNCHER" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; &lt;activity android:name="com.example.giocobambini.BackgroundSoundService" android:label="@string/title_activity_background_sound_service" &gt; &lt;/activity&gt; &lt;/application&gt; &lt;/manifest&gt; </code></pre> <p>Maybe the problem is minSdkVersion="8"!! Maybe for minSdkVersion 8 background music is not supported?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload