Reputation: 187
Am trying to play sounds so I can make a soundboard app, have decided to make it a sliding app to change between activities but it won't let me add the sound pool. Error is happening between the two **. Please help me, am new to coding.
package com.jonatboard.jonat.htssoundboard;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.media.SoundPool;
import android.media.AudioManager;
public class FragmentOne extends Fragment {
SoundPool Clubb1;
int clubb1Id;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Clubb1 = new SoundPool(10, AudioManager.STREAM_MUSIC, 1);
clubb1Id = Clubb1.load**(this, R.raw.clubb1,1)**;
// TODO Auto-generated method stub
return inflater.inflate(R.layout.fragment_one_layout, container, false);
}}
Upvotes: 0
Views: 905
Reputation: 157467
you can use getActivity()
to retrieve the activity's context where FragmentOne
is inflated.
Change
clubb1Id = Clubb1.load(this, R.raw.clubb1,1);
with
clubb1Id = Clubb1.load(getActivity(), R.raw.clubb1,1);
Upvotes: 2