コード例 #1
0
ファイル: Recorder.java プロジェクト: BukT0p/mrapp
  public void startPlayback(float percentage) {
    if (state() == PLAYING_PAUSED_STATE) {
      mSampleStart = System.currentTimeMillis() - mPlayer.getCurrentPosition();
      mPlayer.seekTo((int) (percentage * mPlayer.getDuration()));
      mPlayer.start();
      setState(PLAYING_STATE);
    } else {
      stop();

      mPlayer = new MediaPlayer();
      try {
        mPlayer.setDataSource(mSampleFile.getAbsolutePath());
        mPlayer.setOnCompletionListener(this);
        mPlayer.setOnErrorListener(this);
        mPlayer.prepare();
        mPlayer.seekTo((int) (percentage * mPlayer.getDuration()));
        mPlayer.start();
      } catch (IllegalArgumentException e) {
        setError(INTERNAL_ERROR);
        mPlayer = null;
        return;
      } catch (IOException e) {
        setError(STORAGE_ACCESS_ERROR);
        mPlayer = null;
        return;
      }

      mSampleStart = System.currentTimeMillis();
      setState(PLAYING_STATE);
    }
  }
コード例 #2
0
  public void play(Context c) {
    if (isFirst) {
      stop();

      mPlayer = MediaPlayer.create(c, R.raw.one_small_step);
      mPlayer.setOnCompletionListener(
          new MediaPlayer.OnCompletionListener() {
            public void onCompletion(MediaPlayer mp) {
              stop();
            }
          });
      mPlayer.start();
      isFirst = false;
      Log.d("ISFIRST", "is false");
      return;
    }
    if (!isFirst) {
      if (isPause) {
        mPlayer.start();
        isPause = false;
        return;
      }
      if (!isPause) {
        mPlayer.pause();
        isPause = true;
        return;
      }
    }
  }
コード例 #3
0
ファイル: Speaker.java プロジェクト: gvn182/waveriders
  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();
  }
コード例 #4
0
ファイル: VideoView.java プロジェクト: wangtengfei/reader
 public void onPrepared(MediaPlayer mp) {
   // briefly show the mediacontroller
   mIsPrepared = true;
   if (mOnPreparedListener != null) {
     mOnPreparedListener.onPrepared(mMediaPlayer);
   }
   if (mMediaController != null) {
     mMediaController.setEnabled(true);
   }
   mVideoWidth = mp.getVideoWidth();
   mVideoHeight = mp.getVideoHeight();
   if (mVideoWidth != 0 && mVideoHeight != 0) {
     // Log.i("@@@@", "video size: " + mVideoWidth +"/"+
     // mVideoHeight);
     getHolder().setFixedSize(mVideoWidth, mVideoHeight);
     if (mSurfaceWidth == mVideoWidth && mSurfaceHeight == mVideoHeight) {
       // We didn't actually change the size (it was already at the
       // size
       // we need), so we won't get a "surface changed" callback,
       // so
       // start the video here instead of in the callback.
       if (mSeekWhenPrepared != 0) {
         mMediaPlayer.seekTo(mSeekWhenPrepared);
         mSeekWhenPrepared = 0;
       }
       if (mStartWhenPrepared) {
         mMediaPlayer.start();
         mStartWhenPrepared = false;
         if (mMediaController != null) {
           mMediaController.show();
         }
       } else if (!isPlaying() && (mSeekWhenPrepared != 0 || getCurrentPosition() > 0)) {
         if (mMediaController != null) {
           // Show the media controls when we're paused into a
           // video and make 'em stick.
           mMediaController.show(0);
         }
       }
     }
   } else {
     // We don't know the video size yet, but should start anyway.
     // The video size might be reported to us later.
     if (mSeekWhenPrepared != 0) {
       mMediaPlayer.seekTo(mSeekWhenPrepared);
       mSeekWhenPrepared = 0;
     }
     if (mStartWhenPrepared) {
       mMediaPlayer.start();
       mStartWhenPrepared = false;
     }
   }
 }
コード例 #5
0
 /** Start the url playback by the Android media player. */
 private void playUrl(String url) {
   if (playbackInfo.getSong() == null || !playbackInfo.getSong().getUrl().equals(url)) {
     SongInfo song = mSongMap.get(url);
     playbackInfo.setSong(song);
     prepareFromUrl(url);
     player.start();
     updateSoundSystemInfo();
     soundSystemHandler.postDelayed(progressChangeTracker, PROGRESS_UPDATE_DELAY);
   } else if (!player.isPlaying()) {
     player.start();
     updateSoundSystemInfo();
     soundSystemHandler.postDelayed(progressChangeTracker, PROGRESS_UPDATE_DELAY);
   }
 }
コード例 #6
0
  @Override
  public void onReceive(Context context, Intent intent) {
    // TODO Auto-generated method stub

    switch (intent.getIntExtra("code", 0)) {
      case 0:
        Toast.makeText(context, "Subuh...!!!", Toast.LENGTH_LONG).show();
        break;
      case 1:
        Toast.makeText(context, "Dzuhur...!!!", Toast.LENGTH_LONG).show();
        break;
      case 2:
        Toast.makeText(context, "Ashr...!!!", Toast.LENGTH_LONG).show();
        break;
      case 3:
        Toast.makeText(context, "Maghrib...!!!", Toast.LENGTH_LONG).show();
        break;
      case 4:
        Toast.makeText(context, "Isya...!!!", Toast.LENGTH_LONG).show();
        break;
      default:
        break;
    }
    if (intent.getIntExtra("code", 0) == 0) {
      mp = new MediaPlayer();
      mp = MediaPlayer.create(context, R.raw.rashidmishary_fajr);
      mp.setOnCompletionListener(
          new MediaPlayer.OnCompletionListener() {

            public void onCompletion(MediaPlayer mp) {
              // TODO Auto-generated method stub
              alarm.this.mp.release();
            }
          });
      mp.start();
    } else {
      mp = new MediaPlayer();
      mp = MediaPlayer.create(context, R.raw.makkah);
      mp.setOnCompletionListener(
          new MediaPlayer.OnCompletionListener() {

            public void onCompletion(MediaPlayer mp) {
              // TODO Auto-generated method stub
              alarm.this.mp.release();
            }
          });
      mp.start();
    }
  }
コード例 #7
0
 @Override
 public void onClick(View v) {
   switch (v.getId()) {
     case R.id.play:
       if (!mediaPlayer.isPlaying()) mediaPlayer.start();
       break;
     case R.id.pause:
       if (mediaPlayer.isPlaying()) mediaPlayer.pause();
       else if (!mediaPlayer.isPlaying()) mediaPlayer.start();
       break;
     case R.id.stop:
       if (mediaPlayer.isPlaying()) mediaPlayer.stop();
       break;
   }
 }
コード例 #8
0
ファイル: MainActivity.java プロジェクト: frc1678/super-2016
 public void playSound(int playTrak) {
   if (playTrak == 0) {
     MediaPlayer mp = MediaPlayer.create(this, R.raw.catsound);
     mp.start();
   } else if (playTrak == 1) {
     MediaPlayer mp = MediaPlayer.create(this, R.raw.catsound2);
     mp.start();
   } else if (playTrak == 2) {
     MediaPlayer mp = MediaPlayer.create(this, R.raw.dog);
     mp.start();
   } else if (playTrak == 3) {
     MediaPlayer mp = MediaPlayer.create(this, R.raw.kittenmeow);
     mp.start();
   }
 }
コード例 #9
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();
  }
コード例 #10
0
 @Override
 public void onPrepared(MediaPlayer mp) {
   // Se inicia la reproducción.
   reproductor.start();
   // Se envía un broadcast informativo.
   enviarBroadcast();
 }
コード例 #11
0
 @Override
 public void onPrepared(final MediaPlayer mp) {
   if (progress != null) {
     progress.setVisibility(View.GONE);
   }
   mp.start();
 }
コード例 #12
0
ファイル: Player.java プロジェクト: treejames/SoMusic
 public MusicItem play(
     final Context context, final ArrayList<MusicItem> list, final int position) {
   if (playing == Config.PlayState.STATE_PLAYING) {
     mediaPlayer.reset();
   }
   mediaPlayer =
       MediaPlayer.create(context, Uri.parse("file://" + list.get(position).getFilename()));
   try {
     // mediaPlayer.prepare();
     mediaPlayer.start();
     this.context = context;
     this.list = list;
     this.position = position;
     mediaPlayer.setOnCompletionListener(
         new MediaPlayer.OnCompletionListener() {
           @Override
           public void onCompletion(MediaPlayer mp) {
             Player.this.context.sendBroadcast(new Intent(Config.Broadcast.MUSIC_CHANGE));
             completion(context, list, position);
           }
         });
     playing = Config.PlayState.STATE_PLAYING;
     Player.this.context.sendBroadcast(new Intent(Config.Broadcast.MUSIC_CHANGE));
     return list.get(position);
   } catch (Exception e) {
     e.printStackTrace();
   }
   return null;
 }
コード例 #13
0
        public void onPrepared(MediaPlayer mp) {
          // TODO Auto-generated method stub

          try {
            msurfaceholder.setFixedSize(getPictureWidth(), getPictureHeight());

            int progress = 0;
            progress = getSavedProgress();
            if (progress > 0) {
              mmediaplayer.seekTo(progress);
              sendMsg(VideoConst.MSG_SEEKING);
              mPlayStatus = VideoConst.PLAY_STATUS_SEEKING;
            } else {
              mmediaplayer.start();
              sendMsg(VideoConst.MSG_PLAY_START);
              mPlayStatus = VideoConst.PLAY_STATUS_STARTED;
              if (mOnPBPreparedListener != null) {
                mOnPBPreparedListener.onPrepared(pb);
              }
            }
            if (previewMode == true) {
              setPreviewRect();
            }
          } catch (Exception e) {
            try {
              throw new Exception(e);
            } catch (Exception e1) {
              // TODO Auto-generated catch block
              e1.printStackTrace();
            }
          }
        }
コード例 #14
0
  /** This method runs at a fixed rate. */
  @Override
  public void run() {
    switch (mState) {
      case PREPARED:
        mState = BellRepeaterState.PLAYING;
        mMediaPlayer.start();
        Log.i("BellRepeater", "Media player starting");
        break;
      case PLAYING:
        // Restart the tone
        // mState remains PLAYING
        mMediaPlayer.seekTo(0);
        Log.i("BellRepeater", "Media player restarting");
        break;
      case STOPPED:
        // In theory this shouldn't happen, because the timer should be cancelled.
        // But just in case, do nothing.
        return;
      default:
        break;
    }

    // If it's not the last repetition, set the completion listener to change the state to
    // PREPARED, so that on the next run() we know to use start() rather than seekTo().
    if (++mRepetitionsSoFar < mBellInfo.getTimesToPlay()) {
      mMediaPlayer.setOnCompletionListener(
          new MediaPlayer.OnCompletionListener() {

            @Override
            public void onCompletion(MediaPlayer mp) {
              mState = BellRepeaterState.PREPARED;
              Log.i("BellRepeater", "Media player completed");
            }
          });

      // If it's the last repetition, set the completion listener to release the player and
      // change the state to FINISHED, and cancel the timer (i.e. clean everything up).
    } else {
      mMediaPlayer.setOnCompletionListener(
          new MediaPlayer.OnCompletionListener() {

            @Override
            public void onCompletion(MediaPlayer mp) {
              // The MediaPlayer coming here should be the same one as mMediaPlayer in the
              // BellRepeater class
              if (mp != mMediaPlayer) {
                Log.e(
                    this.getClass().getSimpleName(),
                    "OnCompletionListener mp wasn't the same as mMediaPlayer!");
              }
              mMediaPlayer.release();
              mMediaPlayer = null;
              mState = BellRepeaterState.FINISHED;
              Log.i("BellRepeater", "Over and out");
            }
          });

      mTimer.cancel();
    }
  }
コード例 #15
0
 private void notifyUser() {
   if (!sound) return;
   Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
   v.vibrate(500);
   if (player == null) player = MediaPlayer.create(this, R.raw.dice);
   player.start();
 }
コード例 #16
0
 @Override
 public void play() {
   if (mMediaPlayer.getCurrentPosition() >= mMediaPlayer.getDuration()) {
     mMediaPlayer.seekTo(0);
   }
   mMediaPlayer.start();
 }
コード例 #17
0
ファイル: MPlayer.java プロジェクト: gesulong/Android_lib
  @Override
  public void onPrepared(MediaPlayer mp) {

    if (isPrepare) {
      if (playType == PLAY_TYPE_LOD || playType == PLAY_TYPE_ONDEMAND) {
        // TODO 数据库操作 记忆续播
        MPConPlayManager cPm =
            MPConPlayUtils.findConnectionPlay(currentPosition, parentName, getChildName());
        if (cPm != null && cPm.getEpisodePos() == currentPosition && cPm.getPlayIndex() != 0) {
          mp.seekTo(cPm.getPlayIndex());
        }

        mHandler.sendEmptyMessage(SHOW_CONTROL_ANIMATION);
      }

      mp.start();
      isPrepare = false;

      if (mDialog != null && mDialog.isShowing()) {
        mDialog.dismiss();
      }
      // 判断是否是本地播放或在线点播
      if (playType == PLAY_TYPE_LOD || playType == PLAY_TYPE_ONDEMAND) {
        if (mp.isPlaying() && !mSeekBar.isPressed()) {

          mHandler.sendEmptyMessage(UPDATA_PLAY_TIME);
        }
      }

      mProgressBar.setVisibility(View.INVISIBLE);

      mPlayer.setScreenOnWhilePlaying(true);
    }
  }
コード例 #18
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就收不到短信了
      }
    }
  }
コード例 #19
0
  @Override
  public void onClick(View v) {
    if (v.getId() == R.id.ButtonTestPlayPause) {
      /** ImageButton onClick event handler. Method which start/pause mediaplayer playing */
      try {
        mediaPlayer.setDataSource(
            "http://stream7.cache12.vcdn.vn/fsfsdfdsfdserwrwq3/df399b944be816f5fcf8d0671209dad5/55a0a05d/2015/05/15/6/6/66dd8254b28ea00774d136e251a40a98.mp3"); // setup song from http://www.hrupin.com/wp-content/uploads/mp3/testsong_20_sec.mp3 URL to mediaplayer data source
        mediaPlayer
            .prepare(); // you must call this method after setup the datasource in setDataSource
        // method. After calling prepare() the instance of MediaPlayer starts load
        // data from URL to internal buffer.
      } catch (Exception e) {
        e.printStackTrace();
      }

      mediaFileLengthInMilliseconds =
          mediaPlayer.getDuration(); // gets the song length in milliseconds from URL

      if (!mediaPlayer.isPlaying()) {
        mediaPlayer.start();
        buttonPlayPause.setImageResource(R.drawable.button_pause);
      } else {
        mediaPlayer.pause();
        buttonPlayPause.setImageResource(R.drawable.button_play);
      }

      primarySeekBarProgressUpdater();
    }
  }
コード例 #20
0
ファイル: MainActivity.java プロジェクト: levenkk/OldDemo
  @Override
  public void onSensorChanged(SensorEvent event) {
    // TODO Auto-generated method stub
    float[] values = event.values;
    float x = values[0];
    float y = values[1];
    float z = values[2];

    Log.i("uri", "x轴方向的重力加速度" + x + ";y轴方向的重力加速度" + y + ";z轴方向的重力加速度" + z);
    // 一般在这三个方向的重力加速度达到40就达到了摇晃手机的状态。
    int medumValue = 18;
    if (Math.abs(x) > medumValue || Math.abs(y) > medumValue || Math.abs(z) > medumValue) {
      id_text.setText("屌丝男士");
      try {
        player.start();
        player.setOnCompletionListener(
            new OnCompletionListener() {

              @Override
              public void onCompletion(MediaPlayer mp) {
                // TODO Auto-generated method stub
                player.pause();
                player.seekTo(0);
              }
            });
      } catch (Exception e) {
        e.printStackTrace();
      }
      vibrator.vibrate(500);
      Message msg = new Message();
      msg.what = SENSOR_SHAKE;
      handler.sendMessage(msg);
    }
  }
コード例 #21
0
ファイル: Welcome.java プロジェクト: renxingkai/KuwoMusic
 @Override
 protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.welcome);
   /** 开启欢迎界面延时3秒进入主界面 */
   //        new Handler().postDelayed(new Runnable() {
   //            @Override
   //            public void run() {
   //                Intent intent=new Intent(Welcome.this,MainInterface.class);
   //                Welcome.this.startActivity(intent);
   //                Welcome.this.finish();
   //            }
   //        },delayTime);
   /** 在欢迎界面的同时播放“听音乐用酷我” */
   mediaPlayer = MediaPlayer.create(this, R.raw.kuwo);
   mediaPlayer.start();
   /** 跳过广告按钮 */
   findViewById(R.id.btnStart)
       .setOnClickListener(
           new View.OnClickListener() {
             @Override
             public void onClick(View v) {
               startActivity(new Intent(Welcome.this, MainInterface.class));
             }
           });
 }
コード例 #22
0
ファイル: MusicPicker.java プロジェクト: zst123/p201-packages
  void setSelected(Cursor c) {
    Uri uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
    long newId = mCursor.getLong(mCursor.getColumnIndex(MediaStore.Audio.Media._ID));
    mSelectedUri = ContentUris.withAppendedId(uri, newId);

    mSelectedId = newId;
    if (newId != mPlayingId || mMediaPlayer == null) {
      stopMediaPlayer();
      mMediaPlayer = new MediaPlayer();
      try {
        mMediaPlayer.setDataSource(this, mSelectedUri);
        mMediaPlayer.setOnCompletionListener(this);
        mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
        mMediaPlayer.prepare();
        mMediaPlayer.start();
        mPlayingId = newId;
      } catch (IOException e) {
        MusicLogUtils.e(TAG, "Unable to play track", e);
        /// M: finally just get invalidate list view @{
      } finally {
        getListView().invalidateViews();
      }
      /// @}
    } else if (mMediaPlayer != null) {
      stopMediaPlayer();
      getListView().invalidateViews();
    }
  }
コード例 #23
0
 /** pause */
 public void pause() throws IllegalStateException {
   if (mmediaplayer != null) {
     if (mPlayStatus == VideoConst.PLAY_STATUS_STARTED) {
       try {
         mmediaplayer.pause();
       } catch (IllegalStateException e) {
         e.printStackTrace();
         sendMsg(VideoConst.MSG_INVALID_STATE);
         throw new IllegalStateException(e);
       }
       mPlayStatus = VideoConst.PLAY_STATUS_PAUSED;
       MmpTool.LOG_DBG("pause!");
     } else {
       try {
         mmediaplayer.start();
       } catch (IllegalStateException e) {
         e.printStackTrace();
         sendMsg(VideoConst.MSG_INVALID_STATE);
         throw new IllegalStateException(e);
       }
       mPlayStatus = VideoConst.PLAY_STATUS_STARTED;
       MmpTool.LOG_DBG("play!");
     }
   }
 }
コード例 #24
0
ファイル: AndroidWave.java プロジェクト: tiny2cui/androidwave
  private void playFile() {
    if (playingFile == null || !playingFile.isFile()) resetPlayingFile();
    if (playingFile == null) {
      Toast.makeText(AndroidWave.this, "Cannot play file", Toast.LENGTH_SHORT).show();
      return;
    }
    if (mp != null) mp.stop();
    Log.d("file to play", playingFile.getAbsolutePath());
    mp = MediaPlayer.create(AndroidWave.this, Uri.fromFile(playingFile));
    if (mp == null) {
      Toast.makeText(AndroidWave.this, "Cannot play file", Toast.LENGTH_SHORT).show();
      return;
    }
    mp.setOnCompletionListener(
        new OnCompletionListener() {

          @Override
          public void onCompletion(MediaPlayer arg0) {
            stopPlayFile();
          }
        });
    sm.stop();
    mp.start();
    playButton.setText(R.string.stop);
    playButton.setBackgroundColor(0xFF009900);
  }
コード例 #25
0
  public void play() {
    try {
      if (mp == null) {
        setState(STATE_STARTING);
        initialize();
      }

      if (mp != null) {
        if (!isPlaying()) {
          if (DBG) {
            Log.d(LCAT, "audio is not playing, starting.");
          }
          setVolume(volume);
          if (DBG) {
            Log.d(LCAT, "Play: Volume set to " + volume);
          }
          mp.start();
          setState(STATE_PLAYING);
          paused = false;
          if (remote) {
            startProgressTimer();
          }
        }
        setState(STATE_PLAYING);
      }
    } catch (Throwable t) {
      Log.w(LCAT, "Issue while playing : ", t);
      reset();
    }
  }
コード例 #26
0
 // 服务开始的时候执行
 @Override
 public int onStartCommand(Intent intent, int flags, int startId) {
   if (!player.isPlaying()) {
     player.start();
   }
   return START_STICKY;
 }
コード例 #27
0
ファイル: pear.java プロジェクト: adamfilipczyk/FirstWords
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_pear);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

    // player
    mMediaPlayer = MediaPlayer.create(this, R.raw.pear);
    mMediaPlayer.start();

    // object for the speaker sound
    sound = new SoundPool(1, AudioManager.STREAM_MUSIC, 0);
    soundID = sound.load(this, R.raw.pear, 1);

    // object for the check sound
    click = new SoundPool(1, AudioManager.STREAM_MUSIC, 0);
    soundID = click.load(this, R.raw.click, 1);

    // letters
    findViewById(R.id.pear_p).setOnTouchListener(this);
    findViewById(R.id.pear_e).setOnTouchListener(this);
    findViewById(R.id.pear_a).setOnTouchListener(this);
    findViewById(R.id.pear_r).setOnTouchListener(this);

    // bottom containers drag listener
    findViewById(R.id.bottom_p).setOnDragListener(this);
    findViewById(R.id.bottom_e).setOnDragListener(this);
    findViewById(R.id.bottom_a).setOnDragListener(this);
    findViewById(R.id.bottom_r).setOnDragListener(this);

    // top container drag listener
    findViewById(R.id.top_c).setOnDragListener(this);
  }
コード例 #28
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();
 }
コード例 #29
0
  public void playSong(final ViewHolder holder, String name) {
    if (isPlaying == false) {
      try {

        String path = name;
        gus.setDataSource(root + "/" + path);
        gus.setOnCompletionListener(
            new MediaPlayer.OnCompletionListener() {

              @Override
              public void onCompletion(MediaPlayer mp) {
                holder.myImageButton.setBackgroundResource(R.drawable.play);
                isPlaying = false;
              }
            });
        gus.prepare();
        gus.start();
        Log.d("is playing", "true");
        isPlaying = true;
        holder.myImageButton.setBackgroundResource(R.drawable.pausebtn);

      } catch (Exception e) {
        e.printStackTrace();
      }
    } else {

      gus.pause();
      gus.reset();
      isPlaying = false;
      holder.myImageButton.setBackgroundResource(R.drawable.play);
    }
  }
コード例 #30
0
ファイル: QtFeedback.java プロジェクト: KDE/android-qt
  public void setFileState(int state) {
    switch (state) {
      case 0:
        m_mediaPlayer.pause();
        break;

      case 1:
        m_mediaPlayer.stop();
        try {
          m_mediaPlayer.prepare();
        } catch (IllegalStateException e) {
          e.printStackTrace();
        } catch (IOException e) {
          e.printStackTrace();
        }
        m_mediaPlayer.seekTo(0);
        break;

      case 2:
      case 3:
        m_mediaPlayer.start();
        break;

      default:
        break;
    }
  }