[android-developers] Re: Issue with MediaPLayer

2010-04-28 Thread Mihai Fonoage
What error do you get?

On Apr 26, 7:26 pm, arberb beqi...@gmail.com wrote:
 This is my script:
 public class MainActivity extends Activity {

     @Override
     public void onCreate(Bundle icicle) {
         super.onCreate(icicle);
         this.setContentView(R.layout.main);

         Button myButton = (Button)this.findViewById(R.id.my_button);
         myButton.setOnClickListener(new OnClickListener(){
               �...@override
                public void onClick(View arg0) {
                     MediaPlayer mp =
 MediaPlayer.create(MainActivity.this,
                               R.raw.xd);
                     mp.start();
                     // i.e. react on the end of the music-file:
                     mp.setOnCompletionListener(new
 OnCompletionListener(){

                          // @Override
                          public void onCompletion(MediaPlayer arg0) {
                               // File has ended !!! Wink
                          }
                     });
                }
         });
     }

 }

 but when I click the button in my app the application crashes. Why
 does this happen?

 --
 You received this message because you are subscribed to the Google
 Groups Android Developers group.
 To post to this group, send email to android-developers@googlegroups.com
 To unsubscribe from this group, send email to
 android-developers+unsubscr...@googlegroups.com
 For more options, visit this group 
 athttp://groups.google.com/group/android-developers?hl=en

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Issue with MediaPLayer

2010-04-28 Thread AJ
Before starting the media you need to do following things:-

FileDescriptor fd =
getResources().openRawResourceFd(R.raw.xxx).getFileDescriptor();
mp.setDataSource(fd);
mp.setAudioStreamType(AudioManager.STREAM_RING);
mp.prepareAsync();


For more info check this 
http://developer.android.com/guide/topics/media/index.html

Hope this helps you.

Thanks,
AJ

On Apr 28, 2:59 pm, Mihai Fonoage fonoag...@gmail.com wrote:
 What error do you get?

 On Apr 26, 7:26 pm, arberb beqi...@gmail.com wrote:



  This is my script:
  public class MainActivity extends Activity {

      @Override
      public void onCreate(Bundle icicle) {
          super.onCreate(icicle);
          this.setContentView(R.layout.main);

          Button myButton = (Button)this.findViewById(R.id.my_button);
          myButton.setOnClickListener(new OnClickListener(){
                �...@override
                 public void onClick(View arg0) {
                      MediaPlayer mp =
  MediaPlayer.create(MainActivity.this,
                                R.raw.xd);
                      mp.start();
                      // i.e. react on the end of the music-file:
                      mp.setOnCompletionListener(new
  OnCompletionListener(){

                           // @Override
                           public void onCompletion(MediaPlayer arg0) {
                                // File has ended !!! Wink
                           }
                      });
                 }
          });
      }

  }

  but when I click the button in my app the application crashes. Why
  does this happen?

  --
  You received this message because you are subscribed to the Google
  Groups Android Developers group.
  To post to this group, send email to android-developers@googlegroups.com
  To unsubscribe from this group, send email to
  android-developers+unsubscr...@googlegroups.com
  For more options, visit this group 
  athttp://groups.google.com/group/android-developers?hl=en

 --
 You received this message because you are subscribed to the Google
 Groups Android Developers group.
 To post to this group, send email to android-developers@googlegroups.com
 To unsubscribe from this group, send email to
 android-developers+unsubscr...@googlegroups.com
 For more options, visit this group 
 athttp://groups.google.com/group/android-developers?hl=en

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


Re: [android-developers] Re: Issue with MediaPLayer

2010-04-28 Thread Mihai Fonoage
It should have worked the way he did it (
http://developer.android.com/guide/topics/media/index.html#playraw). The
exception raised should be of more help.

On Wed, Apr 28, 2010 at 8:23 AM, AJ ajeet.invinci...@gmail.com wrote:

 Before starting the media you need to do following things:-

 FileDescriptor fd =
 getResources().openRawResourceFd(R.raw.xxx).getFileDescriptor();
 mp.setDataSource(fd);
 mp.setAudioStreamType(AudioManager.STREAM_RING);
 mp.prepareAsync();


 For more info check this
 http://developer.android.com/guide/topics/media/index.html

 Hope this helps you.

 Thanks,
 AJ

 On Apr 28, 2:59 pm, Mihai Fonoage fonoag...@gmail.com wrote:
  What error do you get?
 
  On Apr 26, 7:26 pm, arberb beqi...@gmail.com wrote:
 
 
 
   This is my script:
   public class MainActivity extends Activity {
 
   @Override
   public void onCreate(Bundle icicle) {
   super.onCreate(icicle);
   this.setContentView(R.layout.main);
 
   Button myButton = (Button)this.findViewById(R.id.my_button);
   myButton.setOnClickListener(new OnClickListener(){
  @Override
  public void onClick(View arg0) {
   MediaPlayer mp =
   MediaPlayer.create(MainActivity.this,
 R.raw.xd);
   mp.start();
   // i.e. react on the end of the music-file:
   mp.setOnCompletionListener(new
   OnCompletionListener(){
 
// @Override
public void onCompletion(MediaPlayer arg0) {
 // File has ended !!! Wink
}
   });
  }
   });
   }
 
   }
 
   but when I click the button in my app the application crashes. Why
   does this happen?
 
   --
   You received this message because you are subscribed to the Google
   Groups Android Developers group.
   To post to this group, send email to
 android-developers@googlegroups.com
   To unsubscribe from this group, send email to
   android-developers+unsubscr...@googlegroups.comandroid-developers%2bunsubscr...@googlegroups.com
   For more options, visit this group athttp://
 groups.google.com/group/android-developers?hl=en
 
  --
  You received this message because you are subscribed to the Google
  Groups Android Developers group.
  To post to this group, send email to android-developers@googlegroups.com
  To unsubscribe from this group, send email to
  android-developers+unsubscr...@googlegroups.comandroid-developers%2bunsubscr...@googlegroups.com
  For more options, visit this group athttp://
 groups.google.com/group/android-developers?hl=en

 --
 You received this message because you are subscribed to the Google
 Groups Android Developers group.
 To post to this group, send email to android-developers@googlegroups.com
 To unsubscribe from this group, send email to
 android-developers+unsubscr...@googlegroups.comandroid-developers%2bunsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/android-developers?hl=en


-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Re: Issue with MediaPLayer

2010-04-28 Thread Bob Kerns
Setting the audio stream to be STREAM_RING makes no sense. Why would
you want to use the volume control for the ringer for your media,
rather than the one for the media??? That's just going to confuse your
users big-time.

Instead, you may want to do
setVolumeControlStream(AudioManager.STREAM_MUSIC), so the volume
controls will affect the proper stream. E.g.:

mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
setVolumeControlStream(AudioManager.STREAM_MUSIC);

setVolumeControlStream(int) is a method on Activity, so depending on
context, you may need to write
yourActivityClassName.this.setVolumeControlStream(AudioManager.STREAM_MUSIC)
instead.


On Apr 28, 5:23 am, AJ ajeet.invinci...@gmail.com wrote:
 Before starting the media you need to do following things:-

 FileDescriptor fd =
 getResources().openRawResourceFd(R.raw.xxx).getFileDescriptor();
 mp.setDataSource(fd);
 mp.setAudioStreamType(AudioManager.STREAM_RING);
 mp.prepareAsync();

 For more info check 
 thishttp://developer.android.com/guide/topics/media/index.html

 Hope this helps you.

 Thanks,
 AJ

 On Apr 28, 2:59 pm, Mihai Fonoage fonoag...@gmail.com wrote:





  What error do you get?

  On Apr 26, 7:26 pm, arberb beqi...@gmail.com wrote:

   This is my script:
   public class MainActivity extends Activity {

       @Override
       public void onCreate(Bundle icicle) {
           super.onCreate(icicle);
           this.setContentView(R.layout.main);

           Button myButton = (Button)this.findViewById(R.id.my_button);
           myButton.setOnClickListener(new OnClickListener(){
                 �...@override
                  public void onClick(View arg0) {
                       MediaPlayer mp =
   MediaPlayer.create(MainActivity.this,
                                 R.raw.xd);
                       mp.start();
                       // i.e. react on the end of the music-file:
                       mp.setOnCompletionListener(new
   OnCompletionListener(){

                            // @Override
                            public void onCompletion(MediaPlayer arg0) {
                                 // File has ended !!! Wink
                            }
                       });
                  }
           });
       }

   }

   but when I click the button in my app the application crashes. Why
   does this happen?

   --
   You received this message because you are subscribed to the Google
   Groups Android Developers group.
   To post to this group, send email to android-developers@googlegroups.com
   To unsubscribe from this group, send email to
   android-developers+unsubscr...@googlegroups.com
   For more options, visit this group 
   athttp://groups.google.com/group/android-developers?hl=en

  --
  You received this message because you are subscribed to the Google
  Groups Android Developers group.
  To post to this group, send email to android-developers@googlegroups.com
  To unsubscribe from this group, send email to
  android-developers+unsubscr...@googlegroups.com
  For more options, visit this group 
  athttp://groups.google.com/group/android-developers?hl=en

 --
 You received this message because you are subscribed to the Google
 Groups Android Developers group.
 To post to this group, send email to android-developers@googlegroups.com
 To unsubscribe from this group, send email to
 android-developers+unsubscr...@googlegroups.com
 For more options, visit this group 
 athttp://groups.google.com/group/android-developers?hl=en

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en