Adding Audio to an App

0 Sam Styles · July 7, 2014
Hi I've been following Travis' guides on Youtube and have run in to a problem while following his instructions in this video here https://www.youtube.com/watch?v=-zGS_zrL0rY&list=PL2F07DBCDCC01493A&index=17">https://www.youtube.com/watch?v=-zGS_zrL0rY&list=PL2F07DBCDCC01493A&index=17

When trying to run the app after adding all the code Travis says to in the video my app will not start and crashes instantly. Prior to adding the code from the video the app works fine. I have noticed that in Travis' video his audio file has a different (musical note) icon next to it

/images/forum/c77bcecf7a5320b2f7ccccdc1085d448.png

whilst when I look at mine it does not.

 /images/forum/659c5287aa6059cbe75710cead147558.png
perhaps this is related? maybe the file just isn't being read properly? Any idea how to fix this?
If that's not the case, here is my code in case I made a typo or the method has changed since the video was created.


package com.example.thenewbonston;

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

public class Splash extends Activity{

MediaPlayer ourSong;

@Override
protected void onCreate(Bundle TravisLoveBacon) {
// TODO Auto-generated method stub
super.onCreate(TravisLoveBacon);
setContentView(R.layout.splash);
ourSong = MediaPlayer.create(Splash.this, R.raw.sound);
ourSong.start();
Thread timer = new Thread(){
public void run(){
try{
sleep(5000);
} catch (InterruptedException e){
e.printStackTrace();
}finally{
Intent openStartingPoint = new Intent("com.example.thenewbonston.STARTINGPOINT");
startActivity(openStartingPoint);
}
}
};
timer.start();
}

@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
ourSong.release();
finish();
}



}


Thank you for your time.

Post a Reply

Replies

Oldest  Newest  Rating
0 Sam Styles · July 8, 2014
Sure thing. Thanks for telling me what the LogCat and stack trace is, people have asked for it before and I wasn't sure. I'm sorry I'm not sure how to interpret this, I think this line


07-07 17:47:18.769: E/MediaPlayer(2173): error (1, -2147483648)


is important because it was the first red line but I've posted the rest below in case. Is there anything else you think would help solve the problem?


07-07 17:47:17.909: W/jdwp(2154): Debugger is telling the VM to exit with code=1
07-07 17:47:17.909: I/dalvikvm(2154): GC lifetime allocation: 16051 bytes
07-07 17:47:18.659: D/dalvikvm(2173): GC_FOR_ALLOC freed 52K, 5% free 2843K/2968K, paused 22ms, total 24ms
07-07 17:47:18.659: I/dalvikvm-heap(2173): Grow heap (frag case) to 3.494MB for 682256-byte allocation
07-07 17:47:18.689: D/dalvikvm(2173): GC_FOR_ALLOC freed 2K, 4% free 3506K/3636K, paused 21ms, total 21ms
07-07 17:47:18.769: E/MediaPlayer(2173): error (1, -2147483648)
07-07 17:47:18.769: D/MediaPlayer(2173): create failed:
07-07 17:47:18.769: D/MediaPlayer(2173): java.io.IOException: Prepare failed.: status=0x1
07-07 17:47:18.769: D/MediaPlayer(2173): at android.media.MediaPlayer.prepare(Native Method)
07-07 17:47:18.769: D/MediaPlayer(2173): at android.media.MediaPlayer.create(MediaPlayer.java:850)
07-07 17:47:18.769: D/MediaPlayer(2173): at com.example.thenewbonston.Splash.onCreate(Splash.java:17)
07-07 17:47:18.769: D/MediaPlayer(2173): at android.app.Activity.performCreate(Activity.java:5231)
07-07 17:47:18.769: D/MediaPlayer(2173): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
07-07 17:47:18.769: D/MediaPlayer(2173): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2172)
07-07 17:47:18.769: D/MediaPlayer(2173): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2270)
07-07 17:47:18.769: D/MediaPlayer(2173): at android.app.ActivityThread.access$800(ActivityThread.java:138)
07-07 17:47:18.769: D/MediaPlayer(2173): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1209)
07-07 17:47:18.769: D/MediaPlayer(2173): at android.os.Handler.dispatchMessage(Handler.java:102)
07-07 17:47:18.769: D/MediaPlayer(2173): at android.os.Looper.loop(Looper.java:136)
07-07 17:47:18.769: D/MediaPlayer(2173): at android.app.ActivityThread.main(ActivityThread.java:5042)
07-07 17:47:18.769: D/MediaPlayer(2173): at java.lang.reflect.Method.invokeNative(Native Method)
07-07 17:47:18.769: D/MediaPlayer(2173): at java.lang.reflect.Method.invoke(Method.java:515)
07-07 17:47:18.769: D/MediaPlayer(2173): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:776)
07-07 17:47:18.769: D/MediaPlayer(2173): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
07-07 17:47:18.769: D/MediaPlayer(2173): at dalvik.system.NativeStart.main(Native Method)
07-07 17:47:18.779: D/AndroidRuntime(2173): Shutting down VM
07-07 17:47:18.779: E/AndroidRuntime(2173): FATAL EXCEPTION: main
07-07 17:47:18.779: E/AndroidRuntime(2173): Process: com.example.thenewbonston, PID: 2173
07-07 17:47:18.779: E/AndroidRuntime(2173): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.thenewbonston/com.example.thenewbonston.Splash}: java.lang.NullPointerException
07-07 17:47:18.779: E/AndroidRuntime(2173): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2208)
07-07 17:47:18.779: E/AndroidRuntime(2173): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2270)
07-07 17:47:18.779: E/AndroidRuntime(2173): at android.app.ActivityThread.access$800(ActivityThread.java:138)
07-07 17:47:18.779: E/AndroidRuntime(2173): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1209)
07-07 17:47:18.779: E/AndroidRuntime(2173): at android.os.Handler.dispatchMessage(Handler.java:102)
07-07 17:47:18.779: E/AndroidRuntime(2173): at android.os.Looper.loop(Looper.java:136)
07-07 17:47:18.779: E/AndroidRuntime(2173): at android.app.ActivityThread.main(ActivityThread.java:5042)
07-07 17:47:18.779: E/AndroidRuntime(2173): at java.lang.reflect.Method.invokeNative(Native Method)
07-07 17:47:18.779: E/AndroidRuntime(2173): at java.lang.reflect.Method.invoke(Method.java:515)
07-07 17:47:18.779: E/AndroidRuntime(2173): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:776)
07-07 17:47:18.779: E/AndroidRuntime(2173): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
07-07 17:47:18.779: E/AndroidRuntime(2173): at dalvik.system.NativeStart.main(Native Method)
07-07 17:47:18.779: E/AndroidRuntime(2173): Caused by: java.lang.NullPointerException
07-07 17:47:18.779: E/AndroidRuntime(2173): at com.example.thenewbonston.Splash.onCreate(Splash.java:18)
07-07 17:47:18.779: E/AndroidRuntime(2173): at android.app.Activity.performCreate(Activity.java:5231)
07-07 17:47:18.779: E/AndroidRuntime(2173): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
07-07 17:47:18.779: E/AndroidRuntime(2173): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2172)
07-07 17:47:18.779: E/AndroidRuntime(2173): ... 11 more
07-07 17:47:18.779: W/dalvikvm(2173): threadid=1: thread exiting with uncaught exception (group=0xb2aa5d58)
07-07 17:47:21.519: I/Process(2173): Sending signal. PID: 2173 SIG: 9


0 William Chamberlain · July 8, 2014
Wrap the startActivity in try/catch and make sure STARTINGPOINT is properly defined in the manifest.
0 Sam Styles · July 8, 2014
Tried what you suggested Will but it still won't work, thank you though!
I think it's safe to say that STARTINGPOINT is properly defined in the manifest as when I remove the MediaPlayer references the app runs smoothly.

Hey Sam thanks for taking the time to respond! After reading what you said it does kind of make sense to me what you say is going wrong, thank you for explaining that too. How did you know where to find the error?
I'm using 4.4.2 so I think it would have been fixed by now, here are the details for the emulator I'm using just in case.

/images/forum/e5dda8bb2b53ff3244b583543b91042c.png

also I'm pretty sure I'm using the .mp3 file and not a shortcut.

/images/forum/7dbbdc9b9e6c486537d53b313e746486.png

Sorry for the slow responses, my posts are still being checked by moderators. Thank you again!
  • 1

Java / Android Development

107,026 followers
About

Very popular language used to create desktop applications, website applets, and Android apps.

Links
Moderators
Bucky Roberts Administrator