Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to play audio music only once while rotation the screen in Android?
    primarykey
    data
    text
    <p>I working on an Audio demo using with media player in Android. I need to play the song only once while I rotate my screen of the emulator.But when I implement this application and I rotate the screen pressing the button of Ctrl+F10 or Ctrl+F11 for landscape and portrait I'm facing the problem of my song is playing to start doubly again I start rotate song is start double and double again and again. Here is my code.</p> <pre><code>public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.audio); init(); imgVw.setImageResource(R.raw.teddy_two); prefs = PreferenceManager.getDefaultSharedPreferences(this); final SharedPreferences.Editor prefsEdit = prefs.edit(); mp = MediaPlayer.create(Audio_Activity.this,R.raw.issaq_tera_by_vishu); mp.setLooping(false); btnChapter.setEnabled(false); prefsEdit.putBoolean("mediaplaying", true); prefsEdit.commit(); mp.start(); System.out.println("Media Plyer Is Start !!!"); mp.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { @Override public void onCompletion(MediaPlayer mp) { // TODO Auto-generated method stub System.out.println("Media Plyer Is Complete !!!"); /*final SharedPreferences.Editor prefsEdit = prefs.edit(); prefsEdit.putBoolean("mediaplaying", false); prefsEdit.commit();*/ btnChapter.setEnabled(true); System.out.println("Music is over and Button is enable !!!!!!"); //mp.start(); } }); @Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); // Checks the orientation of the screen if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) { Toast.makeText(this, "landscape", Toast.LENGTH_SHORT).show(); } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){ Toast.makeText(this, "portrait", Toast.LENGTH_SHORT).show(); } } } </code></pre> <p>I have add the audio.xml file in layout-land folder in res directory </p> <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".MainActivity" &gt; &lt;ImageView android:id="@+id/display_Images" android:layout_width="fill_parent" android:layout_height="260dp" android:background="@android:color/black" /&gt; &lt;TableLayout android:id="@+id/table_Audio" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="300dp" &gt; &lt;TableRow android:layout_width="wrap_content" android:layout_height="wrap_content" &gt; &lt;Button android:id="@+id/btnPause_Resume" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/audio" /&gt; &lt;Button android:id="@+id/btnChapter" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/chapter" &gt; &lt;/Button&gt; &lt;/TableRow&gt; &lt;/TableLayout&gt; &lt;/RelativeLayout&gt; </code></pre> <p>Here is my AndroidMeniFest.xml file</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.audio_demo" android:versionCode="1" android:versionName="1.0" &gt; &lt;uses-sdk android:minSdkVersion="10" android:targetSdkVersion="17" /&gt; &lt;uses-permission android:name="android.permission.READ_PHONE_STATE" /&gt; &lt;application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" &gt; &lt;activity android:name="com.audio_demo.Audio_Activity" android:label="@string/app_name" android:screenOrientation="portrait" &gt; &lt;intent-filter&gt; &lt;action android:name="android.intent.action.MAIN" /&gt; &lt;category android:name="android.intent.category.LAUNCHER" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; &lt;/application&gt; &lt;/manifest&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload