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..


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;

    protected void onCreate(Bundle savedInstanceState) {

    toolbar = (Toolbar)findViewById(;

        tabLayout = (TabLayout)findViewById(;
        viewPager = (ViewPager)findViewById(;
        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");


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



Source: java

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.