media player still plays in all activities when device is rotated even though locked to portrait

This is my first time dealing with media player, i have a sound play when the app starts but the problem i am having is a sound is played again when device is rotated even though it is locked to portrait, this is happening in all activities and i only want the sound to play when the app starts and not again!
i have tried adding..

android:configChanges=”orientation|keyboard|keyboardHidden|screenSize”

to the manifest in mainactivity as advised by someone but this is not working and seems odd to me!

here is my main activity java code with the media player set up.

public class MainActivity extends AppCompatActivity {

    Toolbar toolbar;
    TabLayout tabLayout;
    ViewPager viewPager;
    ViewPagerAdapter viewPagerAdapter;

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

    toolbar = (Toolbar)findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        tabLayout = (TabLayout)findViewById(R.id.tablayout);
        viewPager = (ViewPager)findViewById(R.id.viewPager);
        viewPagerAdapter = new ViewPagerAdapter(getSupportFragmentManager());
        viewPagerAdapter.addFragments(new HomeFragment(),"Welcome");
        viewPagerAdapter.addFragments(new TopThreeFragment(),"Main Display");
        viewPagerAdapter.addFragments(new TopPaidFragment(),"Options");
        viewPagerAdapter.addFragments(new ForthTestFragment(),"news");
        viewPagerAdapter.addFragments(new About(),"About");

        viewPager.setAdapter(viewPagerAdapter);
        tabLayout.setupWithViewPager(viewPager);

        final MediaPlayer mp = MediaPlayer.create(this, R.raw.firsteps);
        mp.start();

    }

}

Source: java

Leave a Reply