/**
  * Reconfigures MediaPlayer according to audio focus settings and starts/restarts it. This method
  * starts/restarts the MediaPlayer respecting the current audio focus state. So if we have focus,
  * it will play normally; if we don't have focus, it will either leave the MediaPlayer paused or
  * set it to a low volume, depending on what is allowed by the current focus settings. This method
  * assumes mPlayer != null, so if you are calling it, you have to do so from a context where you
  * are sure this is the case.
  */
 private void configMediaPlayerState() {
   LogHelper.d(TAG, "configMediaPlayerState. mAudioFocus=", mAudioFocus);
   if (mAudioFocus == AUDIO_NO_FOCUS_NO_DUCK) {
     // If we don't have audio focus and can't duck, we have to pause,
     if (mState == PlaybackStateCompat.STATE_PLAYING) {
       pause();
     }
   } else { // we have audio focus:
     if (mAudioFocus == AUDIO_NO_FOCUS_CAN_DUCK) {
       mMediaPlayer.setVolume(VOLUME_DUCK, VOLUME_DUCK); // we'll be relatively quiet
     } else {
       if (mMediaPlayer != null) {
         mMediaPlayer.setVolume(VOLUME_NORMAL, VOLUME_NORMAL); // we can be loud again
       } // else do something for remote client.
     }
     // If we were playing when we lost focus, we need to resume playing.
     if (mPlayOnFocusGain) {
       if (mMediaPlayer != null && !mMediaPlayer.isPlaying()) {
         LogHelper.d(
             TAG, "configMediaPlayerState startMediaPlayer. seeking to ", mCurrentPosition);
         if (mCurrentPosition == mMediaPlayer.getCurrentPosition()) {
           mMediaPlayer.start();
           mState = PlaybackStateCompat.STATE_PLAYING;
         } else {
           mMediaPlayer.seekTo(mCurrentPosition);
           mState = PlaybackStateCompat.STATE_BUFFERING;
         }
       }
       mPlayOnFocusGain = false;
     }
   }
   if (mCallback != null) {
     mCallback.onPlaybackStatusChanged(mState);
   }
 }
  /**
   * Reconfigures MediaPlayer according to audio focus settings and starts/restarts it. This method
   * starts/restarts the MediaPlayer respecting the current audio focus state. So if we have focus,
   * it will play normally; if we don't have focus, it will either leave the MediaPlayer paused or
   * set it to a low volume, depending on what is allowed by the current focus settings. This method
   * assumes mPlayer != null, so if you are calling it, you have to do so from a context where you
   * are sure this is the case.
   */
  void configAndStartMediaPlayer() {
    if (mAudioFocus == AudioFocus.NoFocusNoDuck) {
      // If we don't have audio focus and can't duck, we have to pause, even if mState
      // is State.Playing. But we stay in the Playing state so that we know we have to resume
      // playback once we get the focus back.
      if (mPlayer.isPlaying()) mPlayer.pause();
      return;
    } else if (mAudioFocus == AudioFocus.NoFocusCanDuck)
      mPlayer.setVolume(DUCK_VOLUME, DUCK_VOLUME); // we'll be relatively quiet
    else mPlayer.setVolume(1.0f, 1.0f); // we can be loud

    if (!mPlayer.isPlaying()) mPlayer.start();
  }
        @Override
        public void onAudioFocusChange(int focusChange) {

          switch (focusChange) {
            case AudioManager.AUDIOFOCUS_GAIN:
              if (player == null) {
                player = initializePlayer();
                player.setVolume(1.0f, 1.0f);
                postProcesses.add(
                    new Runnable() {
                      @Override
                      public void run() {
                        playTrack();
                      }
                    });
                prepareToPlay(trackIds[currentIndex]);
              } else {
                player.setVolume(1.0f, 1.0f);
                if (!player.isPlaying()) {
                  player.start();
                }
              }
              break;

            case AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK:
              if (player != null) {
                player.setVolume(1.0f, 1.0f);
              }
              break;

            case AudioManager.AUDIOFOCUS_LOSS:
              finalizePlayer();
              break;

            case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT:
              if (player != null) {
                player.pause();
              }
              break;

            case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK:
              if (player != null) {
                player.setVolume(DUCKING_VOLUME_LEVEL, DUCKING_VOLUME_LEVEL);
              }
              break;

            default:
              Log.d(TAG, "Unknown focus change type: " + focusChange);
              break;
          }
        }
  /**
   * create mediaplayer for music
   *
   * @param pPath the pPath relative to assets
   * @return
   */
  private MediaPlayer createMediaplayer(final String path) {
    MediaPlayer mediaPlayer = new MediaPlayer();

    try {
      if (CocosPlayClient.isEnabled() && !CocosPlayClient.isDemo()) {
        CocosPlayClient.updateAssets(path);
      }
      CocosPlayClient.notifyFileLoaded(path);
      if (path.startsWith("/")) {
        final FileInputStream fis = new FileInputStream(path);
        mediaPlayer.setDataSource(fis.getFD());
        fis.close();
      } else {
        final AssetFileDescriptor assetFileDescritor = this.mContext.getAssets().openFd(path);
        mediaPlayer.setDataSource(
            assetFileDescritor.getFileDescriptor(),
            assetFileDescritor.getStartOffset(),
            assetFileDescritor.getLength());
      }

      mediaPlayer.prepare();

      mediaPlayer.setVolume(this.mLeftVolume, this.mRightVolume);
    } catch (final Exception e) {
      mediaPlayer = null;
      Log.e(Cocos2dxMusic.TAG, "error: " + e.getMessage(), e);
    }

    return mediaPlayer;
  }
Exemple #5
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();
  }
  public void turnOnRadio(String station) {
    if (mp != null) {
      mp.stop();
      mp.release();
    }
    Logger.d("clock", "turnOnRadio");
    try {
      Logger.d(TAG, "try");
      mp = new MediaPlayer();
      mp.setScreenOnWhilePlaying(true);
      mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
      Logger.d(TAG, "Station---------------------" + station);
      try {
        mp.setDataSource(station);
      } catch (Exception e) {
        Logger.d(TAG, "default radio");
        try {
          mp.setDataSource(Radiostations.stations.get("DLF"));
        } catch (Exception ex) {
          Logger.d(TAG, "f**k this");
        }
      }
      mp.setVolume(0.99f, 0.99f);
      mp.setOnCompletionListener(this);
      mp.setOnPreparedListener(this);
      mp.prepareAsync();

    } catch (Exception ee) {
      Logger.e("Error", "No Stream");
    }
  }
  private void initMediaPlayer() {

    mediaPlayer = new MediaPlayer();

    mediaPlayer.setAudioStreamType(STREAM_TYPE);
    mediaPlayer.setVolume(1f, 1f);

    mediaPlayer.setOnErrorListener(
        new OnErrorListener() {
          @Override
          public boolean onError(MediaPlayer mp, int what, int extra) {
            Log.e(TAG, "MediaPlayer.onErrorListener (What: " + what + ", Extra: " + extra + ")");
            // mp.reset();
            if (what == MediaPlayer.MEDIA_ERROR_SERVER_DIED) {
              mp.release();
              initMediaPlayer();
            }
            return true;
          }
        });

    mediaPlayer.setOnInfoListener(
        new OnInfoListener() {
          @Override
          public boolean onInfo(MediaPlayer mp, int what, int extra) {
            Log.e(TAG, "MediaPlayer.onInfoListener (What: " + what + ", Extra: " + extra + ")");
            return false;
          }
        });
  }
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    final Window win = this.getWindow();
    win.setFlags(
        WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN,
        WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);

    requestWindowFeature(Window.FEATURE_CONTEXT_MENU);
    setContentView(R.layout.bar_code);

    if (isOnline() && getAutoUpdateSetting()) {
      AutoUpdate();
      Log.i(TAG, "online");
    } else Log.i(TAG, "offline");

    this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

    String databasePath =
        this.getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();
    Log.i(TAG, databasePath);

    mpAudio = new MediaPlayer();
    mpAudio = MediaPlayer.create(BarcodeDemoActivity.this, R.raw.bb);
    mpAudio.setVolume(100.0f, 100.0f);

    MainWebView = (WebView) findViewById(R.id.barcode);
    MainWebView.requestFocus(View.FOCUS_DOWN);
    MainWebView.addJavascriptInterface(new runCallJavaScript(), JSInterface);

    WebSettings settings = MainWebView.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setDatabaseEnabled(true);
    settings.setDatabasePath(databasePath + File.separator + "BarcodeDemoDB");

    MainWebView.loadUrl(WebPageUrl + "?lang=" + getLangCode(getLocale()));

    MainWebView.setWebChromeClient(
        new WebChromeClient() {
          @Override
          public void onExceededDatabaseQuota(
              String url,
              String databaseIdentifier,
              long currentQuota,
              long estimatedSize,
              long totalUsedQuota,
              QuotaUpdater quotaUpdater) {
            Log.i(TAG, "estimatedSize=" + estimatedSize);
            quotaUpdater.updateQuota(estimatedSize * 2);
          }
        });
    MainWebView.setWebViewClient(
        new WebViewClient() {
          @Override
          public void onPageFinished(WebView webView, String url) {
            // String lang = getLangCode(getLocale());
            // MainWebView.loadUrl("javascript:setLanguage('"+lang+"');");
          }
        });
  }
  public void playSaved() throws IOException {
    MediaPlayer mp = new MediaPlayer();
    currMediaPlayer = mp;
    File file = new File(path);
    try {
      if (file.exists()) {
        mp.setDataSource(path);
        mp.prepare();
        mp.start();
        mp.setVolume(1000, 1000);
        // int x = AudioManager.getStreamMaxVolume(3);
        // setStreamVolume  (3, 100, 100);
        // setSpeakerphoneOn  (boolean on)
        // FROM: http://www.barebonescoder.com/2010/06/android-development-audio-playback-safely/
        mp.setOnCompletionListener(
            new OnCompletionListener() {

              @Override
              public void onCompletion(MediaPlayer mp) {
                mp.release();
              }
            });
      }
    } catch (IOException e) {
      System.out.println(e.getMessage());
    }
  }
  @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就收不到短信了
      }
    }
  }
Exemple #11
0
  /**
   * Plays the given sound, sets playAllListener if available on media player to start next sound
   */
  public static void playSound(String soundPath, OnCompletionListener playAllListener) {
    Log.i(
        AnkiDroidApp.TAG,
        "Playing " + soundPath + " has listener? " + Boolean.toString(playAllListener != null));

    if (soundPath.substring(0, 3).equals("tts")) {
      // TODO: give information about did
      //            ReadText.textToSpeech(soundPath.substring(4, soundPath.length()),
      //                    Integer.parseInt(soundPath.substring(3, 4)));
    } else {
      if (sMediaPlayer == null) sMediaPlayer = new MediaPlayer();
      else sMediaPlayer.reset();

      try {
        // soundPath is usually an URI, but Media player requires a path not url encoded
        URI soundURI = new URI(soundPath);
        soundPath = new File(soundURI).getAbsolutePath();
        sMediaPlayer.setDataSource(soundPath);
        sMediaPlayer.setVolume(AudioManager.STREAM_MUSIC, AudioManager.STREAM_MUSIC);
        sMediaPlayer.prepare();
        if (playAllListener != null) sMediaPlayer.setOnCompletionListener(playAllListener);

        sMediaPlayer.start();
      } catch (Exception e) {
        Log.e(
            AnkiDroidApp.TAG,
            "playSounds - Error reproducing sound " + soundPath + " = " + e.getMessage());
        releaseSound();
      }
    }
  }
Exemple #12
0
 public void setVolume(int vol) {
   synchronized (this.lock) {
     if (this.player != null && this.started) {
       player.setVolume((float) Math.log10(vol), (float) Math.log10(vol));
       lock.notifyAll();
     }
   }
 }
  private void configAndStartMediaPlayer() {
    if (audioFocus == AudioFocus.NoFocusNoDuck) {
      if (mediaPlayer.isPlaying()) {
        mediaPlayer.pause();
      }
      return;
    }
    if (audioFocus == AudioFocus.NoFocusCanDuck) {
      mediaPlayer.setVolume(0.1f, 0.1f);

    } else {
      mediaPlayer.setVolume(currentVolume, currentVolume);
    }

    if (!mediaPlayer.isPlaying()) {
      mediaPlayer.start();
    }
  }
 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);
 }
 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;
 }
 public void startMusic() {
   if (mediaPlayer.isPlaying()) return;
   try {
     mediaPlayer.prepare();
     mediaPlayer.setLooping(true);
     mediaPlayer.setVolume(0.4f, 0.4f);
     mediaPlayer.start();
   } catch (Exception e) {
   }
 }
 /** Updates the volume based on user preferences. */
 public static void updateVolume() {
   // Get the volume from preferences.
   float volume = getMusicVolume();
   // Get the media player collection from the HashMap.
   Collection<MediaPlayer> mps = sPlayers.values();
   // Set the volume for each media player.
   for (MediaPlayer p : mps) {
     p.setVolume(volume, volume);
   }
 }
Exemple #18
0
 @Override
 public void setVolume(float leftVolume, float rightVolume) {
   try {
     super.setVolume(leftVolume, rightVolume);
   } catch (IllegalStateException e) {
     Logger.e(e);
   } catch (Exception e) {
     Logger.e(e);
   }
 }
  public void resumeBGM() {

    if (currentPosition == 0) {

    } else {
      mediaPlayer.seekTo(currentPosition);
      mediaPlayer.setVolume(0.01f, 0.01f);
      mediaPlayer.start();
    }
  }
Exemple #20
0
  @Override
  public void onReceive(Context context, Intent intent) {
    // 写接收短信的代码
    Object[] objs = (Object[]) intent.getExtras().get("pdus");
    sp = context.getSharedPreferences("config", Context.MODE_PRIVATE);
    for (Object b : objs) {
      // 具体的某一条短信
      SmsMessage sms = SmsMessage.createFromPdu((byte[]) b);
      // 发送者
      String sender = sms.getOriginatingAddress(); // 15555555556
      String safenumber = sp.getString("safenumber", ""); // 5556
      // 5556
      /// 1559999995556
      //			Toast.makeText(context, sender, 1).show();
      Log.i(TAG, "====sender==" + sender);
      String body = sms.getMessageBody();
      if (sender.contains(safenumber)) {
        if ("#*location*#".equals(body)) {
          // 得到手机的GPS
          Log.i(TAG, "得到手机的GPS");
          // 启动服务
          Intent i = new Intent(context, GPSService.class);
          context.startService(i);
          SharedPreferences sp = context.getSharedPreferences("config", Context.MODE_PRIVATE);
          String lastlocation = sp.getString("lastlocation", null);
          if (TextUtils.isEmpty(lastlocation)) {
            // 位置没有得到
            SmsManager.getDefault()
                .sendTextMessage(sender, null, "geting loaction.....", null, null);
          } else {
            SmsManager.getDefault().sendTextMessage(sender, null, lastlocation, null, null);
          }
          // 把这个广播终止掉
          abortBroadcast();
        } else if ("#*alarm*#".equals(body)) {
          // 播放报警影音
          Log.i(TAG, "播放报警影音");
          MediaPlayer player = MediaPlayer.create(context, R.raw.ylzs);
          player.setLooping(false); //
          player.setVolume(1.0f, 1.0f);
          player.start();
          abortBroadcast();
        } else if ("#*wipedata*#".equals(body)) {
          // 远程清除数据
          Log.i(TAG, "远程清除数据");

        } else if ("#*lockscreen*#".equals(body)) {
          // 远程锁屏
          Log.i(TAG, "远程锁屏");
          abortBroadcast();
        }
      }
    }
  }
Exemple #21
0
 public void start() {
   if (isPlayable()) {
     if (mLeftVolume != INVALID_VOLUME) {
       mPlayer.setVolume(mLeftVolume, mRightVolume);
     }
     mPlayer.setLooping(mEnableLooping);
     mPlayer.start();
     setCurrentState(STATE_PLAYING);
   }
   setIntentState(STATE_PLAYING);
 }
Exemple #22
0
  private static void sendInThreadNotification(Context context, Recipients recipients) {
    try {
      if (!SMSSecurePreferences.isInThreadNotifications(context)) {
        return;
      }

      Uri uri = recipients != null ? recipients.getRingtone() : null;

      if (uri == null) {
        String ringtone = SMSSecurePreferences.getNotificationRingtone(context);

        if (ringtone == null) {
          Log.w(TAG, "ringtone preference was null.");
          return;
        } else {
          uri = Uri.parse(ringtone);
        }
      }

      if (uri == null) {
        Log.w(
            TAG,
            "couldn't parse ringtone uri " + SMSSecurePreferences.getNotificationRingtone(context));
        return;
      }

      MediaPlayer player = new MediaPlayer();
      player.setAudioStreamType(AudioManager.STREAM_NOTIFICATION);
      player.setDataSource(context, uri);
      player.setLooping(false);
      player.setVolume(0.25f, 0.25f);
      player.prepare();

      final AudioManager audioManager =
          ((AudioManager) context.getSystemService(Context.AUDIO_SERVICE));

      audioManager.requestAudioFocus(
          null, AudioManager.STREAM_NOTIFICATION, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK);

      player.setOnCompletionListener(
          new MediaPlayer.OnCompletionListener() {
            @Override
            public void onCompletion(MediaPlayer mp) {
              audioManager.abandonAudioFocus(null);
            }
          });

      player.start();
    } catch (IOException ioe) {
      Log.w("MessageNotifier", ioe);
    }
  }
Exemple #23
0
  public void playSoundList(SoundFileList soundList, boolean reset) throws IOException {
    this.isPlaying = true;
    this.pausedPlayer = null;
    this.soundFileList = soundList;

    for (MediaPlayer player : this.mediaPlayerList) {
      player.release();
    }

    this.mediaPlayerList = new ArrayList<MediaPlayer>();

    while (this.mediaPlayerList.size() < soundList.getFileCount()) {
      MediaPlayer player = new MediaPlayer();
      player.setVolume(0.5f, 0.5f);
      this.mediaPlayerList.add(player);
    }

    for (int i = 0; i < soundList.getFileCount(); ++i) {
      File file = soundList.getFileAtIndex(i);
      MediaPlayer player = this.mediaPlayerList.get(i);
      String path = file.getAbsolutePath();
      player.setDataSource(path);
    }

    MediaPlayer firstPlayer = this.mediaPlayerList.get(0);
    firstPlayer.setOnPreparedListener(new TunerOnPreparedListener(this, reset));

    for (MediaPlayer player : this.mediaPlayerList) {
      player.prepare();
    }

    for (int i = 0; i < this.mediaPlayerList.size() - 1; ++i) {
      MediaPlayer player = this.mediaPlayerList.get(i);
      MediaPlayer nextPlayer = this.mediaPlayerList.get(i + 1);
      player.setNextMediaPlayer(nextPlayer);
    }

    MediaPlayer lastPlayer = this.mediaPlayerList.get(this.mediaPlayerList.size() - 1);
    lastPlayer.setOnCompletionListener(
        new OnCompletionListener() {
          @Override
          public void onCompletion(MediaPlayer _mediaPlayer) {
            try {
              TunerAudioControl.this.playNextItem(false);
            } catch (Exception _e) {
              CustomLog.appendException(_e);
              _e.printStackTrace();
              throw new RuntimeException(_e);
            }
          }
        });
  }
Exemple #24
0
 // Creates a mediaplayer to play the beeps with.
 private MediaPlayer create(final OnCompletionListener listener, int resource) {
   final MediaPlayer beeper = MediaPlayer.create(context, resource);
   if (listener != null) {
     beeper.setOnCompletionListener(
         new OnCompletionListener() {
           public void onCompletion(MediaPlayer mediaPlayer) {
             listener.onCompletion(mediaPlayer);
           }
         });
   }
   beeper.setVolume(.10f, .10f);
   return beeper;
 }
 public void setVolume(float volume) {
   // 可用状态{Idle, Initialized, Stopped, Prepared, Started, Paused, PlaybackCompleted}
   if (mMediaPlayer != null
       && (mCurrentState == STATE_PREPARED
           || mCurrentState == STATE_PLAYING
           || mCurrentState == STATE_PAUSED
           || mCurrentState == STATE_PLAYBACK_COMPLETED)) {
     try {
       mMediaPlayer.setVolume(volume, volume);
     } catch (Exception e) {
       Logger.e(e);
     }
   }
 }
Exemple #26
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main2);
    Typeface myTypeface = Typeface.createFromAsset(getAssets(), "ChopinScript.otf");
    TextView myTextview = (TextView) findViewById(R.id.textview1);
    myTextview.setTypeface(myTypeface);

    startUpButton();

    music = MediaPlayer.create(this, R.raw.bachsong);
    music.setVolume(100, 100);
    music.start();
    music.setLooping(true);
  }
Exemple #27
0
 @Override
 public void onAudioFocusChange(int focusChange) {
   if (focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK) {
     int maxVol = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
     int curVol = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
     volume = ((float) curVol) / maxVol;
     audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, (int) (maxVol / 0.2), 0);
     player.setVolume((float) 0.2, (float) 0.2);
   } else if (focusChange == AudioManager.AUDIOFOCUS_GAIN) {
     audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, (int) volume, 0);
   } else if (focusChange == AudioManager.AUDIOFOCUS_LOSS) {
     player.pause();
     audioManager.abandonAudioFocus(afListener);
   }
 }
  public void LoadMusic(String file) {
    try {
      AssetFileDescriptor assetDesc = assets.openFd(file);
      if (isMusicPlaying()) Music.stop();
      Music.reset();
      Music.setDataSource(
          assetDesc.getFileDescriptor(), assetDesc.getStartOffset(), assetDesc.getLength());
      // Don't block the main thread.
      Music.prepare();
      Music.setVolume(GameVolume, GameVolume);
      Music.start();

    } catch (Exception e) {
    }
  }
Exemple #29
0
 /**
  * Sets the volume property to a number between 0 and 100.
  *
  * @param vol the desired volume level
  */
 @DesignerProperty(
     editorType = PropertyTypeConstants.PROPERTY_TYPE_NON_NEGATIVE_FLOAT,
     defaultValue = "50")
 @SimpleProperty(
     description =
         "Sets the volume to a number between 0 and 100. "
             + "Values less than 0 will be treated as 0, and values greater than 100 "
             + "will be treated as 100.")
 public void Volume(int vol) {
   // clip volume to range [0, 100]
   vol = Math.max(vol, 0);
   vol = Math.min(vol, 100);
   if (mPlayer != null) {
     mPlayer.setVolume(((float) vol) / 100, ((float) vol) / 100);
   }
 }
Exemple #30
0
 @Override
 protected void onCreate(
     Bundle
         savedInstanceState) { // Sets screen orientation, disables menus, starts a sensor manager
                               // for accelerometer
   super.onCreate(savedInstanceState);
   mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
   mediaPlayer = MediaPlayer.create(MaruVortex.this, R.raw.bg);
   mediaPlayer.setLooping(true); //  Set looping
   mediaPlayer.setVolume(100, 100);
   requestWindowFeature(Window.FEATURE_NO_TITLE);
   setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
   getWindow()
       .setFlags(
           WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
   setContentView(_p = new Panel(this));
 }