amir_70
amir_70

Reputation: 930

audio file does not play in android

I have an android app with two buttons play button and a pause button . If the play button is pressed then a mp3 file should be started. The pause button will pause the music. Here is my code :

public class MainActivity extends AppCompatActivity {

private MediaPlayer mp ;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    final Button playBtn = (Button) findViewById(R.id.play_id);

    mp = MediaPlayer.create(this , R.raw.aroom);

    playBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mp.start();
        }
    });

    final Button pauseBtn = (Button) findViewById(R.id.pause_id);
    playBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mp.pause();
        }
    });
}
}

and here is my logcat :

07-10 18:31:11.010 15628-15628/? I/art: Late-enabling -Xcheck:jni
07-10 18:31:11.154 15628-15643/com.example.amir.myapplication E/HAL: load: id=gralloc != hmi->id=gralloc
07-10 18:31:11.224 15628-15628/com.example.amir.myapplication W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --debuggable --instruction-set=arm --instruction-set-features=smp,div,atomic_ldrd_strd --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=cortex-a15 --instruction-set-features=default --dex-file=/data/app/com.example.amir.myapplication-2/split_lib_dependencies_apk.apk --oat-file=/data/dalvik-cache/arm/data@[email protected]@[email protected]) because non-0 exit status
07-10 18:31:11.485 15628-15628/com.example.amir.myapplication W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --debuggable --instruction-set=arm --instruction-set-features=smp,div,atomic_ldrd_strd --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=cortex-a15 --instruction-set-features=default --dex-file=/data/app/com.example.amir.myapplication-2/split_lib_slice_0_apk.apk --oat-file=/data/dalvik-cache/arm/data@[email protected]@[email protected]) because non-0 exit status
07-10 18:31:11.543 15628-15628/com.example.amir.myapplication W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --debuggable --instruction-set=arm --instruction-set-features=smp,div,atomic_ldrd_strd --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=cortex-a15 --instruction-set-features=default --dex-file=/data/app/com.example.amir.myapplication-2/split_lib_slice_1_apk.apk --oat-file=/data/dalvik-cache/arm/data@[email protected]@[email protected]) because non-0 exit status
07-10 18:31:11.596 15628-15628/com.example.amir.myapplication W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --debuggable --instruction-set=arm --instruction-set-features=smp,div,atomic_ldrd_strd --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=cortex-a15 --instruction-set-features=default --dex-file=/data/app/com.example.amir.myapplication-2/split_lib_slice_2_apk.apk --oat-file=/data/dalvik-cache/arm/data@[email protected]@[email protected]) because non-0 exit status
07-10 18:31:11.648 15628-15628/com.example.amir.myapplication W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --debuggable --instruction-set=arm --instruction-set-features=smp,div,atomic_ldrd_strd --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=cortex-a15 --instruction-set-features=default --dex-file=/data/app/com.example.amir.myapplication-2/split_lib_slice_3_apk.apk --oat-file=/data/dalvik-cache/arm/data@[email protected]@[email protected]) because non-0 exit status
07-10 18:31:11.701 15628-15628/com.example.amir.myapplication W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --debuggable --instruction-set=arm --instruction-set-features=smp,div,atomic_ldrd_strd --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=cortex-a15 --instruction-set-features=default --dex-file=/data/app/com.example.amir.myapplication-2/split_lib_slice_4_apk.apk --oat-file=/data/dalvik-cache/arm/data@[email protected]@[email protected]) because non-0 exit status
07-10 18:31:11.757 15628-15628/com.example.amir.myapplication W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --debuggable --instruction-set=arm --instruction-set-features=smp,div,atomic_ldrd_strd --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=cortex-a15 --instruction-set-features=default --dex-file=/data/app/com.example.amir.myapplication-2/split_lib_slice_5_apk.apk --oat-file=/data/dalvik-cache/arm/data@[email protected]@[email protected]) because non-0 exit status
07-10 18:31:11.810 15628-15628/com.example.amir.myapplication W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --debuggable --instruction-set=arm --instruction-set-features=smp,div,atomic_ldrd_strd --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=cortex-a15 --instruction-set-features=default --dex-file=/data/app/com.example.amir.myapplication-2/split_lib_slice_6_apk.apk --oat-file=/data/dalvik-cache/arm/data@[email protected]@[email protected]) because non-0 exit status
07-10 18:31:11.875 15628-15628/com.example.amir.myapplication W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --debuggable --instruction-set=arm --instruction-set-features=smp,div,atomic_ldrd_strd --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=cortex-a15 --instruction-set-features=default --dex-file=/data/app/com.example.amir.myapplication-2/split_lib_slice_7_apk.apk --oat-file=/data/dalvik-cache/arm/data@[email protected]@[email protected]) because non-0 exit status
07-10 18:31:11.948 15628-15628/com.example.amir.myapplication W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --debuggable --instruction-set=arm --instruction-set-features=smp,div,atomic_ldrd_strd --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=cortex-a15 --instruction-set-features=default --dex-file=/data/app/com.example.amir.myapplication-2/split_lib_slice_8_apk.apk --oat-file=/data/dalvik-cache/arm/data@[email protected]@[email protected]) because non-0 exit status
07-10 18:31:12.009 15628-15628/com.example.amir.myapplication W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --debuggable --instruction-set=arm --instruction-set-features=smp,div,atomic_ldrd_strd --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --runtime-arg -Xms64m --runtime-arg -Xmx512m --instruction-set-variant=cortex-a15 --instruction-set-features=default --dex-file=/data/app/com.example.amir.myapplication-2/split_lib_slice_9_apk.apk --oat-file=/data/dalvik-cache/arm/data@[email protected]@[email protected]) because non-0 exit status
07-10 18:31:12.015 15628-15628/com.example.amir.myapplication W/System: ClassLoader referenced unknown path: /data/app/com.example.amir.myapplication-2/lib/arm
07-10 18:31:12.033 15628-15628/com.example.amir.myapplication I/InstantRun: starting instant run server: is main process
07-10 18:31:12.173 15628-15628/com.example.amir.myapplication I/HwCust: Constructor found for class android.app.HwCustHwWallpaperManagerImpl
07-10 18:31:12.204 15628-15628/com.example.amir.myapplication W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
07-10 18:31:12.336 15628-15628/com.example.amir.myapplication I/HwCust: Constructor found for class android.widget.HwCustTextViewImpl
07-10 18:31:12.345 15628-15628/com.example.amir.myapplication I/HwCust: Constructor found for class android.widget.HwCustTextViewImpl
07-10 18:31:12.359 15628-15628/com.example.amir.myapplication I/MediaPlayer: setDataSource(40, 69464, 9958560)
07-10 18:31:12.405 15628-15628/com.example.amir.myapplication I/HwSecImmHelper: mSecurityInputMethodService is null
07-10 18:31:12.526 15628-15709/com.example.amir.myapplication E/HAL: load: id=gralloc != hmi->id=gralloc
07-10 18:31:12.527 15628-15709/com.example.amir.myapplication I/OpenGLRenderer: Initialized EGL, version 1.4
07-10 18:31:12.653 15628-15628/com.example.amir.myapplication W/art: Before Android 4.1, method int android.support.v7.widget.ListViewCompat.lookForSelectablePosition(int, boolean) would have incorrectly overridden the package-private method in android.widget.ListView
07-10 18:31:12.738 15628-15628/com.example.amir.myapplication I/HwSecImmHelper: mSecurityInputMethodService is null

can anyone help ?

edit

I have no external storage on my device. Huawei ascend mate 7 and no sd card on it. I simply have a mp3 file in /res/raw folder and I want to play it when the button is pressed. I've followed an udacity course and this is one of the quizzes. When I saw the solution the code is the one I've provided but I can't play the sound. I mean I've copied and pasted the code on my android studio but for me it does not work.

solution:

after some editing the code i found the answer . silly mistake from me . there are 2 listener for pause and play but i named both of them the same name . the second listener should be on pause button not play button pauseBtn.setOnClickListener

Upvotes: 0

Views: 84

Answers (2)

cjnash
cjnash

Reputation: 1248

If you are reading an mp3 file from a card, such as an SD card, then you most likely need to declare runtime permissions. All the info you need on runtime permissions can be found here:

https://developer.android.com/training/permissions/requesting.html

Also make sure that you have static permissions in your manifest as well, like so:

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

Upvotes: 0

Erald Haka
Erald Haka

Reputation: 182

Have you any file at "aroom"? Have you declared any permission on Manifest ?

Upvotes: 1

Related Questions