I've a resource directory called "raw" in the "res" folder, but still can't access it through my code. The problem occurs when trying to declare the MediaPlayer variable.
public class MainActivity extends AppCompatActivity {
private MediaPlayer pSong;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
pSong = MediaPlayer.create(this,R.raw.rando);
Button playButton = (Button) findViewById(R.id.play);
playButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(MainActivity.this,"Play", Toast.LENGTH_SHORT).show();
}
});
}
}
Click on Build
-> Rebuild Project
and then click File
-> Sync Project with Gradle Files
Click on Build
-> Rebuild Project
and then click Tools
-> Android
-> Sync Project with Gradle Files
Rebuilding and Syncing did not work for me. Had to restart Android Studio.
Android Studio 4+: Go to File -> Invalidate Caches / Restart this will let android studio to index the raw files.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With