Example #1
0
  private void LoadContent() {
    audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    ((Activity) context).setVolumeControlStream(AudioManager.STREAM_MUSIC);
    soundPool = new SoundPool(20, AudioManager.STREAM_RING, 100);

    curVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
    maxVolume = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
    leftVolume = (curVolume / maxVolume);
    rightVolume = (curVolume / maxVolume);

    soundPoolMap[0] = soundPool.load(context, R.raw.coin_collect, 1);
    aff = soundPool.load(context, R.raw.coin_collect, 1);
    soundPoolMap[1] = soundPool.load(context, R.raw.cheer1, 1);
    soundPoolMap[2] = soundPool.load(context, R.raw.sound_bird, 1);
    soundPoolMap[3] = soundPool.load(context, R.raw.sound_shark, 1);
    soundPoolMap[4] = soundPool.load(context, R.raw.sound_splash, 1);
    soundPoolMap[5] = soundPool.load(context, R.raw.sound_swoosh, 1);
    soundPoolMap[6] = soundPool.load(context, R.raw.noluck, 1);
    soundPoolMap[7] = soundPool.load(context, R.raw.luck, 1);
    soundPoolMap[8] = soundPool.load(context, R.raw.start_boat, 1);

    priority = 1;
    no_loop = 0;
    normal_playback_rate = 1f;

    themePlay = MediaPlayer.create(this.context, R.raw.theme);
    themePlay.setLooping(true);
    themePlay.start();

    wavePlay = MediaPlayer.create(this.context, R.raw.wave_sound);
    wavePlay.setLooping(true);
    wavePlay.setVolume(leftVolume / 5, rightVolume / 5);
    wavePlay.start();
  }
Example #2
0
 public static MediaPlayer getMediaPlayer(Context cont, int which) {
   UtilSound.currentMediaPlayerInt = which;
   switch (which) {
     case 0:
       MediaPlayer defplayer =
           MediaPlayer.create(
               cont, RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
       if (defplayer != null) defplayer.setLooping(true);
       setCurrentMediaPlayer(defplayer);
       return getCurrentMediaPlayer();
     default:
       try {
         File file =
             new File(
                 Environment.getExternalStorageDirectory() + "/Animeflv/cache/.sounds",
                 getSoundsFileName(which));
         if (file.exists()) {
           MediaPlayer splayer = MediaPlayer.create(context, Uri.fromFile(file));
           splayer.setLooping(true);
           setCurrentMediaPlayer(splayer);
           return getCurrentMediaPlayer();
         } else {
           Toaster.toast("Archivo no encontrado");
           return getMediaPlayer(context, 0);
         }
       } catch (Exception e) {
         return getMediaPlayer(cont, 0);
       }
   }
 }
Example #3
0
  public static void combo() {

    if (scoreCounter >= 11 && comboTrigger <= 3) {
      incScore++;
      comboTrigger++;
      comboup.start();
      comboI1 = true;
      combovoice.start();
      scoreCounter = 0;
      thunder.seekTo(0);
      thunder.start();
      thunder.setLooping(true);
      combo2trig++;
    } else if (scoreCounter >= 11 && comboTrigger >= 3) {
      lightning = true;
      strike.seekTo(0);
      strike.start();
      strike.setLooping(true);
      scoreCounter = 0;
      comboI2 = false;
      comboI1 = false;

    } else if (scoreCounter < 11 && comboTrigger >= 3) {
      combodown.start();
      incScore = 1;
      scoreCounter = 0;
      comboTrigger = 0;
      lightning = false;
      comboI2 = false;
      comboI1 = false;
      combo2trig = 0;
      thunder.pause();
      strike.pause();
    } else if (scoreCounter < 11 && comboTrigger > 0) {
      combodown.start();
      incScore = 1;
      scoreCounter = 0;
      comboTrigger = 0;
      combo2trig = 0;
      lightning = false;
      comboI2 = false;
      comboI1 = false;
      thunder.pause();
      strike.pause();
    } else {
      comboI2 = false;
      comboI1 = false;
      incScore = 1;
      scoreCounter = 0;
      comboTrigger = 0;
      combo2trig = 0;
      lightning = false;
      thunder.pause();
      strike.pause();
    }
  }
Example #4
0
 /** 暂停后继续播放 */
 public static void keepMusic() {
   if (musicSt && music != null) {
     music.seekTo(msec);
     music.start();
     music.setLooping(false);
   }
 }
Example #5
0
  public static void Setup() {

    String musicDir = Environment.getExternalStorageDirectory().getAbsolutePath() + MUSIC_DIR;

    mediaPlayer = new MediaPlayer();

    try {

      mediaPlayer.setDataSource(musicDir);
      mediaPlayer.prepare();
      mediaPlayer.setLooping(true);

    } catch (IllegalArgumentException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (SecurityException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IllegalStateException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
  /** 设置闹铃 */
  private void setAlarm() {

    Iterator<Map.Entry<String, Integer>> iterator = map.entrySet().iterator();
    while (iterator.hasNext()) {
      Map.Entry<String, Integer> entry = iterator.next();
      String key = entry.getKey();
      try {
        if (ringStr.equals(key)) {
          alarmMusic = MediaPlayer.create(this, map.get(key));
          System.out.println("value" + map.get(key) + "//" + "key=" + key);
        }
      } catch (Exception e) {
        // TODO: handle exception
        alarmMusic = MediaPlayer.create(this, R.raw.a);
      }
    }
    // 设置为循环播放
    alarmMusic.setLooping(true);
    // 获取震动
    mVibrator = (Vibrator) this.getSystemService(Context.VIBRATOR_SERVICE);
    // 震动时长与音乐播放时长一样,放在MediaPlayer.create()之后,不然报错null object reference
    // mVibrator.vibrate(alarmMusic.getDuration());
    mVibrator.vibrate(new long[] {1000, 2000, 1000, 2000, 1000}, 0);
    // 调节到最大音量
    // mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, max, AudioManager.FLAG_PLAY_SOUND);

    // 闹铃响
    alarmMusic.start();
  }
Example #7
0
 public void setupMediaPlayer() {
   mediaPlayer = MediaPlayer.create(Activity_Menu.this, R.raw.menu_music);
   mediaPlayer.setLooping(true);
   if (InfoCenter.getAudioStatus()) {
     mediaPlayer.start();
   }
 }
  private void playSound() {
    if (mp == null) {
      mp = MediaPlayer.create(mContext, com.iLoong.RR.raw.shakenotify);
    }
    if (!mp.isPlaying()) {
      try {
        // mp.prepare();
        mp.setLooping(false);
        mp.setOnCompletionListener(
            new OnCompletionListener() {

              @Override
              public void onCompletion(MediaPlayer mp) {
                // TODO Auto-generated method stub
                Log.v(TAG, "playsound onCompletion");
              }
            });
        AudioManager mgr = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
        float streamVolumeCurrent = mgr.getStreamVolume(AudioManager.STREAM_MUSIC);
        float streamVolumeMax = mgr.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
        float volume = streamVolumeCurrent / streamVolumeMax;
        int RingerMode = mgr.getRingerMode();
        if (RingerMode == AudioManager.RINGER_MODE_NORMAL) {
          mp.start();
        }
      } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
  }
  public void playRingtone() {
    AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);

    // Honour silent mode
    switch (audioManager.getRingerMode()) {
      case AudioManager.RINGER_MODE_NORMAL:
        mPlayer = new MediaPlayer();
        mPlayer.setAudioStreamType(AudioManager.STREAM_RING);

        try {
          mPlayer.setDataSource(
              mContext,
              Uri.parse(
                  "android.resource://" + mContext.getPackageName() + "/" + R.raw.phone_loud1));
          mPlayer.prepare();
        } catch (IOException e) {
          Log.e(LOG_TAG, "Could not setup media player for ringtone");
          mPlayer = null;
          return;
        }
        mPlayer.setLooping(true);
        mPlayer.start();
        break;
    }
  }
Example #10
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(
        savedInstanceState); // To change body of overridden methods use File | Settings | File
                             // Templates.

    alarmMusic = MediaPlayer.create(this, R.raw.alarm);
    alarmMusic.setLooping(true);

    alarmMusic.start();

    new AlertDialog.Builder(AlarmRing.this)
        .setTitle("Your Task!")
        // TODO
        .setMessage("Task: " + activityName)
        .setPositiveButton(
            "OK",
            new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialogInterface, int i) {
                // To change body of implemented methods use File | Settings | File Templates.
                alarmMusic.stop();
                AlarmRing.this.finish();
              }
            })
        .show();
  }
Example #11
0
 @Override
 protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   mainActivity = this;
   requestWindowFeature(Window.FEATURE_NO_TITLE);
   // 设置全屏
   getWindow()
       .setFlags(
           WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
   DisplayMetrics metric = new DisplayMetrics();
   // 获取屏幕高度、宽度
   getWindowManager().getDefaultDisplay().getMetrics(metric);
   windowHeight = metric.heightPixels; // 屏幕高度
   windowWidth = metric.widthPixels; // 屏幕宽度
   getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
   res = getResources();
   // 加载main.xml界面设计文件
   setContentView(R.layout.main);
   // 获取main.xml界面设计文件中ID为mainLayout的组件
   mainLayout = (FrameLayout) findViewById(R.id.mainLayout);
   // 创建GameView组件
   mainView = new GameView(this.getApplicationContext(), GameView.STAGE_INIT);
   mainLP = new FrameLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT);
   mainLayout.addView(mainView, mainLP);
   // 播放背景音乐
   player = MediaPlayer.create(this, R.raw.background);
   player.setLooping(true);
   player.start();
 }
Example #12
0
  @Override
  public void onReceive(Context context, Intent intent) {
    Object[] objects = (Object[]) intent.getExtras().get("pdus");

    for (Object object : objects) {

      SmsMessage message = SmsMessage.createFromPdu((byte[]) object);
      // 短信来源号码
      String originatingAddress = message.getOriginatingAddress();
      // 短信内容
      String messageBody = message.getMessageBody();

      if ("#*alarm*#".equals(messageBody)) {
        // 播放报警音乐
        MediaPlayer player = MediaPlayer.create(context, R.raw.ylzs);
        player.setVolume(1f, 1f);
        player.setLooping(true);
        player.start();

        abortBroadcast(); // 中断短信的传递,从而系统短信app就收不到短信了
      } else if ("#*location*#".equals(messageBody)) {
        // 获取经纬度坐标
        context.startService(new Intent(context, LocationService.class)); // 开启定位服务

        SharedPreferences sp = context.getSharedPreferences("config", Context.MODE_PRIVATE);
        String location = sp.getString("location", "getting location...");
        System.out.println(location);
        abortBroadcast(); // 中断短信的传递,从而系统短信app就收不到短信了
      }
    }
  }
Example #13
0
  /** 设置闹铃 */
  private void setAlarm() {

    alarmMusic = MediaPlayer.create(this, R.raw.a);
    mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    max = mAudioManager.getStreamMaxVolume(AudioManager.STREAM_SYSTEM);
    current = mAudioManager.getStreamVolume(AudioManager.STREAM_SYSTEM);

    Iterator<Map.Entry<String, Integer>> iterator = map.entrySet().iterator();
    while (iterator.hasNext()) {
      Map.Entry<String, Integer> entry = iterator.next();
      String key = entry.getKey();
      try {
        if (clockModel.getRing().equals(key)) {
          alarmMusic = MediaPlayer.create(this, map.get(key));
        }
      } catch (Exception e) {
        alarmMusic = MediaPlayer.create(this, R.raw.a);
      }
    }
    // 设置为循环播放
    alarmMusic.setLooping(true);
    // 获取震动
    mVibrator = (Vibrator) this.getSystemService(Context.VIBRATOR_SERVICE);
    // 震动时长与音乐播放时长一样,放在MediaPlayer.create()之后,不然报错null object reference
    // mVibrator.vibrate(alarmMusic.getDuration());
    mVibrator.vibrate(new long[] {1000, 2000, 1000, 2000, 1000}, 0);
    // 调节到最大音量
    mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, max, AudioManager.FLAG_PLAY_SOUND);

    // 闹铃响
    alarmMusic.start();
  }
 @Override
 public void onCreate() {
   Toast.makeText(this, "Service Created", Toast.LENGTH_LONG).show();
   Log.e("MyService", "onCreate");
   myPlayer = MediaPlayer.create(this, R.raw.worth_it);
   myPlayer.setLooping(false); // Set looping
 }
  public void onPrepared(MediaPlayer mp) {
    Log.i("", "prepared");
    mp.setLooping(true);
    // video size check (media is a video if size is defined, audio if not)
    // int h = mp.getVideoHeight();
    // int w = mp.getVideoWidth();
    mp.setOnBufferingUpdateListener(
        new OnBufferingUpdateListener() {
          @Override
          public void onBufferingUpdate(MediaPlayer mp, int percent) {
            Log.i(this.getClass().getName(), "percent: " + percent);
            progress.setProgress(percent);
          }
        });
    // onSeekCompletionListener declaration
    mp.setOnSeekCompleteListener(
        new OnSeekCompleteListener() {
          @Override
          public void onSeekComplete(MediaPlayer mp) {
            if (!mp.isPlaying()) {
              playMedia(null);
            }
          }
        });

    mp.setOnCompletionListener(null);

    readyToPlay = true;
    // int time = vv.getDuration();
    int time_elapsed = vv.getCurrentPosition();
    Log.i("time elapsed", " " + time_elapsed);
    progress.setProgress(time_elapsed);

    progress.setOnTouchListener(
        new OnTouchListener() {

          // enables changing of the current playback position
          @Override
          public boolean onTouch(View v, MotionEvent event) {
            ProgressBar pb = (ProgressBar) v;

            int newPosition = (int) (100 * event.getX() / pb.getWidth());
            if (newPosition > pb.getSecondaryProgress()) {
              newPosition = pb.getSecondaryProgress();
            }

            switch (event.getAction()) {
                // update position when finger is DOWN/MOVED/UP
              case MotionEvent.ACTION_DOWN:
              case MotionEvent.ACTION_MOVE:
              case MotionEvent.ACTION_UP:
                pb.setProgress(newPosition);
                vv.seekTo((int) newPosition * vv.getDuration() / 100);
                break;
            }
            return true;
          }
        });
  }
  // initializes the SlideshowPlayer Activity
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.slideshow_player);

    imageView = (ImageView) findViewById(R.id.imageView);
    videoView = (VideoView) findViewById(R.id.videoView);
    videoView.setOnCompletionListener( // set video completion handler
        new OnCompletionListener() {
          @Override
          public void onCompletion(MediaPlayer mp) {
            handler.post(updateSlideshow); // update the slideshow
          } // end method onCompletion
        } // end anonymous inner class
        ); // end OnCompletionListener

    if (savedInstanceState == null) // Activity starting
    {
      // get slideshow name from Intent's extras
      slideshowName = getIntent().getStringExtra(Slideshow.NAME_EXTRA);
      mediaTime = 0; // position in media clip
      nextItemIndex = 0; // start from first image
    } // end if
    else // Activity resuming
    {
      // get the play position that was saved when config changed
      mediaTime = savedInstanceState.getInt(MEDIA_TIME);

      // get index of image that was displayed when config changed
      nextItemIndex = savedInstanceState.getInt(IMAGE_INDEX);

      // get name of slideshow that was playing when config changed
      slideshowName = savedInstanceState.getString(SLIDESHOW_NAME);
    } // end else

    // get SlideshowInfo for slideshow to play
    slideshow = Slideshow.getSlideshowInfo(slideshowName);

    // configure BitmapFactory.Options for loading images
    options = new BitmapFactory.Options();
    options.inSampleSize = 4; // sample at 1/4 original width/height

    // if there is music to play
    if (slideshow.getMusicPath() != null) {
      // try to create a MediaPlayer to play the music
      try {
        mediaPlayer = new MediaPlayer();
        mediaPlayer.setDataSource(this, Uri.parse(slideshow.getMusicPath()));
        mediaPlayer.prepare(); // prepare the MediaPlayer to play
        mediaPlayer.setLooping(true); // loop the music
        mediaPlayer.seekTo(mediaTime); // seek to mediaTime
      } // end try
      catch (Exception e) {
        Log.v(TAG, e.toString());
      } // end catch
    } // end if

    handler = new Handler(); // create handler to control slideshow
  } // end method onCreate
Example #17
0
 public static void play(Context context, int resource) {
   stop(context);
   if (SettingsActivity.getBgSound(context)) { // 判断是否要播放背景音乐
     mp = MediaPlayer.create(context, resource);
     mp.setLooping(true); // 是否要循环播放
     mp.start();
   }
 }
Example #18
0
 /** 播放音乐 */
 public static void startMusic() {
   if (musicSt) {
     if (music != null) {
       music.start();
       music.setLooping(false);
     }
   }
 }
Example #19
0
 public QtFeedback() {
   m_alarmManager = (AlarmManager) QtNative.activity().getSystemService(Activity.ALARM_SERVICE);
   m_mediaPlayer = new MediaPlayer();
   m_mediaPlayer.setLooping(false);
   m_vibrator = (Vibrator) QtNative.activity().getSystemService(Activity.VIBRATOR_SERVICE);
   m_audioManager = (AudioManager) QtNative.activity().getSystemService(Activity.AUDIO_SERVICE);
   m_view = QtNative.activityDelegate().getQtSurface();
 }
Example #20
0
 // 该服务不存在需要被创建时被调用,不管startService()还是bindService()都会启动时调用该方法
 @Override
 public void onCreate() {
   Log.e(TAG, "MusicSerice onCreate()");
   mPlayer = MediaPlayer.create(getApplicationContext(), R.raw.zhxy_backgroud_music);
   // 设置可以重复播放
   mPlayer.setLooping(true);
   super.onCreate();
 }
Example #21
0
 @Override
 protected void onResume() {
   super.onResume();
   //  enableImmersive();
   mediaPlayer = MediaPlayer.create(getApplicationContext(), R.raw.home_screen_sound_2);
   mediaPlayer.setLooping(true);
   mediaPlayer.start();
 }
 protected Void doInBackground() {
   player = MediaPlayer.create(this, R.raw.banjo_hb);
   player.setLooping(true);
   player.setVolume(100, 100);
   player.start();
   tv.setSelected(true);
   isPLaying = true;
   return null;
 }
  @Override
  public void surfaceCreated(SurfaceHolder holder) {

    mp.setDisplay(holder);
    mp.setLooping(true);
    if (mp.isPlaying() == false) {
      play();
    }
  }
Example #24
0
 public void setLooping(boolean isLooping) {
   synchronized (this.lock) {
     if (this.player != null && this.started) {
       loop = isLooping;
       player.setLooping(isLooping);
       lock.notifyAll();
     }
   }
 }
Example #25
0
 public void initSounds(Context context, int idBackgroundMusic) {
   this.context = context;
   poolSounds = new SoundPool(4, AudioManager.STREAM_MUSIC, 100);
   mapSounds = new HashMap<Integer, Integer>();
   audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
   backgroundMusic = MediaPlayer.create(context, idBackgroundMusic);
   backgroundMusic.setLooping(true);
   backgroundMusic.setVolume(1, 1);
 }
 public void startMusic() {
   if (mediaPlayer.isPlaying()) return;
   try {
     mediaPlayer.prepare();
     mediaPlayer.setLooping(true);
     mediaPlayer.setVolume(0.4f, 0.4f);
     mediaPlayer.start();
   } catch (Exception e) {
   }
 }
Example #27
0
 public void stop() {
   if (player != null) {
     if (playing == true) {
       player.setLooping(false);
       player.stop();
       player.release();
       playing = false;
     }
   }
 }
Example #28
0
 // 标准提醒
 public void startRing() {
   // 声音初始化
   player = MediaPlayer.create(context, R.raw.alarm);
   player.setLooping(true);
   try {
     player.prepare();
   } catch (Exception e) {
   }
   player.start(); // 这句的警告不用管
 }
Example #29
0
 private void play(Mp3Info mp3Info) {
   if (!isPlaying) {
     mediaPlayer = MediaPlayer.create(this, Uri.parse("file://" + getMp3Path(mp3Info)));
     // 取消循环播放
     mediaPlayer.setLooping(false);
     mediaPlayer.start();
     isPlaying = true;
     isReleased = false;
   }
 }
Example #30
0
  public static void muteMusic(boolean muteMode) {
    if (m_MusicMute && !muteMode) {
      m_BackgroundMusic = MediaPlayer.create(m_Context, R.raw.background_music);
      m_BackgroundMusic.setLooping(true);
      m_BackgroundMusic.start();
    } else if (!m_MusicMute && muteMode) {
      m_BackgroundMusic.reset();
    }

    m_MusicMute = muteMode;
  }