当前位置: 首页>>代码示例>>Java>>正文


Java MediaPlayer.isPlaying方法代码示例

本文整理汇总了Java中android.media.MediaPlayer.isPlaying方法的典型用法代码示例。如果您正苦于以下问题:Java MediaPlayer.isPlaying方法的具体用法?Java MediaPlayer.isPlaying怎么用?Java MediaPlayer.isPlaying使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.media.MediaPlayer的用法示例。


在下文中一共展示了MediaPlayer.isPlaying方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: playAllAsync

import android.media.MediaPlayer; //导入方法依赖的package包/类
public void playAllAsync() {
    Thread r = new Thread() {


        @Override
        public void  run() {
            int counter = 0;
            for (MediaPlayer m : loadedSounds) {
                Log.d(MainActivity.LOG_TAG, "Playing sound no. " + counter);
                m.start();
                while (m.isPlaying()) {
                    try {
                        Thread.sleep(100,0); // lower cpu if we wait and not just busy wait
                    } catch (InterruptedException e) { e.printStackTrace();}
                }

                counter++;
            }

            raisePlayBackFinishEvent();
        }
     };


    r.start();
}
 
开发者ID:yonixw,项目名称:mi-band-2,代码行数:27,代码来源:SoundHelper.java

示例2: resume

import android.media.MediaPlayer; //导入方法依赖的package包/类
/**
 * resume playing
 *
 * @return
 */
public synchronized UDAudio resume() {
    final MediaPlayer player = getMediaPlayer();
    if (player != null && player.isPlaying() == false) {
        try {
            if (player.getCurrentPosition() > 0) {
                player.start();
            } else {
                play(mUriOrName, mLoopTimes);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return this;
}
 
开发者ID:alibaba,项目名称:LuaViewPlayground,代码行数:21,代码来源:UDAudio.java

示例3: stop

import android.media.MediaPlayer; //导入方法依赖的package包/类
/**
 * stop playing audio
 *
 * @return
 */
public synchronized UDAudio stop() {
    final MediaPlayer player = getMediaPlayer();
    if (player != null && player.isPlaying()) {
        try {
            player.stop();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return this;
}
 
开发者ID:alibaba,项目名称:LuaViewPlayground,代码行数:17,代码来源:UDAudio.java

示例4: playRecording

import android.media.MediaPlayer; //导入方法依赖的package包/类
public static void playRecording(Context context, MediaPlayer mediaPlayer, String recordingName) {
    try {
        if (mediaPlayer.isPlaying()) {
            mediaPlayer.stop();
            mediaPlayer.reset(); //Before a setDataSource call, you need to reset MP obj.
            mediaPlayer.setDataSource(context.getFilesDir().getAbsolutePath() + "/" + recordingName);
            mediaPlayer.prepare();
            mediaPlayer.start();
        } else {
            mediaPlayer.reset(); //Before a setDataSource call, you need to reset MP obj.
            mediaPlayer.setDataSource(context.getFilesDir().getAbsolutePath() + "/" + recordingName);
            mediaPlayer.prepare();
            mediaPlayer.start();
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
开发者ID:Cesarsk,项目名称:Say_it,代码行数:19,代码来源:UtilityRecordings.java

示例5: onPrepared

import android.media.MediaPlayer; //导入方法依赖的package包/类
@Override
public void onPrepared(MediaPlayer mp) {
    if (mp != null) {
        synchronized (mp) {
            try {
                if (mp.isPlaying() == false) {
                    mp.start();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
 
开发者ID:alibaba,项目名称:LuaViewPlayground,代码行数:15,代码来源:UDAudio.java

示例6: onClickCheckBox

import android.media.MediaPlayer; //导入方法依赖的package包/类
@Override
public void onClickCheckBox(int p,CheckBox checkBox,TextView title)
{
    HashMap<String,String> map = mArrayList.get(p);

    if(checkBox.isChecked())
    {
        title.setPaintFlags(title.getPaintFlags()|Paint.STRIKE_THRU_TEXT_FLAG);
        MediaPlayer player = MediaPlayer.create(getContext(),R.raw.ding);
        player.setAudioStreamType(AudioManager.STREAM_MUSIC);

        if(player.isPlaying())
            player.stop();
        else
            player.start();


        mTodo.updateData(keyName,1,map.get("id"));
        mArrayList = mTodo.getData(keyName);

    }
    else
    {
        title.setPaintFlags(title.getPaintFlags()&(~Paint.STRIKE_THRU_TEXT_FLAG));
        mTodo.updateData(keyName,0,map.get("id"));
        mArrayList = mTodo.getData(keyName);

    }
}
 
开发者ID:Salman544,项目名称:Todo_App,代码行数:30,代码来源:TodoFragment.java

示例7: startPlayer

import android.media.MediaPlayer; //导入方法依赖的package包/类
private void startPlayer() {
  mPlayer = new MediaPlayer();
  mPlayer.setOnErrorListener(mErrorListener);

  try {
    isAlarmRinging = true;
    // add vibration to alarm alert if it is set
    //if (App.getState().settings().vibrate()) {
    mVibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
    mHandler.post(mVibrationRunnable);
    //}
    // Player setup is here
    String ringtone;// = App.getState().settings().ringtone();
    //if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
    //    && ringtone.startsWith("content://media/external/")
    //    && checkSelfPermission(
    //    Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_DENIED) {
    ringtone = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM).toString();
    //}
    mPlayer.setDataSource(this, Uri.parse(ringtone));
    mPlayer.setLooping(true);
    mPlayer.setAudioStreamType(AudioManager.STREAM_ALARM);
    mPlayer.setVolume(mVolumeLevel, mVolumeLevel);
    mPlayer.prepare();
    mPlayer.start();

    //if (App.getState().settings().ramping()) {
    //  mHandler.postDelayed(mVolumeRunnable, VOLUME_INCREASE_DELAY);
    //} else {
    mPlayer.setVolume(MAX_VOLUME, MAX_VOLUME);
    //}
  } catch (Exception e) {
    isAlarmRinging = false;
    if (mPlayer.isPlaying()) {
      mPlayer.stop();
    }
    stopSelf();
  }
}
 
开发者ID:Arjun-sna,项目名称:LocationAware,代码行数:40,代码来源:LocationAwareService.java

示例8: voicePause

import android.media.MediaPlayer; //导入方法依赖的package包/类
public static void voicePause(MediaPlayer player, Chronometer chronometer) {
    // 判断音乐是否在播放
    if (player != null && player.isPlaying()) {
        setChronometer(chronometer, Constant.CHRONOMETER_STOP);
        // 暂停音乐播放器
        player.pause();
    }
}
 
开发者ID:lpy19930103,项目名称:MinimalismJotter,代码行数:9,代码来源:RecoderManager.java

示例9: onPrepared

import android.media.MediaPlayer; //导入方法依赖的package包/类
@Override
public void onPrepared(MediaPlayer mediaPlayer) {
    progress_bar.setVisibility(View.GONE);
    onVideoSizeChanged(mediaPlayer);
    if (!mediaPlayer.isPlaying()) {
        isPlay = true;
        mediaPlayer.start();
    }
}
 
开发者ID:gitxuyulin,项目名称:EditorImageAndText,代码行数:10,代码来源:VideoActivity.java

示例10: stopMedia

import android.media.MediaPlayer; //导入方法依赖的package包/类
/**
 * 使用完MediaPlayer需要回收资源。MediaPlayer是很消耗系统资源的,所以在使用完MediaPlayer,不要等待系统自动回收,最好是主动回收资源。
 */
private void stopMedia(MediaPlayer mediaPlayer) {
    if (mediaPlayer != null && mediaPlayer.isPlaying()) {
        mediaPlayer.stop();
        mediaPlayer.release();
        mediaPlayer = null;
    }

}
 
开发者ID:orchidTJJ,项目名称:getword,代码行数:12,代码来源:MainActivity.java

示例11: pause

import android.media.MediaPlayer; //导入方法依赖的package包/类
@ReactMethod
public void pause(final Integer key) {
  MediaPlayer player = this.playerPool.get(key);
  if (player != null && player.isPlaying()) {
    player.pause();
  }
}
 
开发者ID:remobile,项目名称:react-native-audio,代码行数:8,代码来源:RCTAudio.java

示例12: stop

import android.media.MediaPlayer; //导入方法依赖的package包/类
@ReactMethod
public void stop(final Integer key) {
  MediaPlayer player = this.playerPool.get(key);
  if (player != null && player.isPlaying()) {
    player.stop();
  }
}
 
开发者ID:remobile,项目名称:react-native-audio,代码行数:8,代码来源:RCTAudio.java

示例13: releaseMemory

import android.media.MediaPlayer; //导入方法依赖的package包/类
public void releaseMemory() {
    for(int i=0;i<audioMap.size();i++) {
        MediaPlayer mp = audioMap.remove(i);
        if (mp.isPlaying()) {
            mp.stop();
        }
        mp.release();
    }
    audioMap = null;
    isPlaying = false;
    currentId = CURRENT_NOT_PLAYING;
}
 
开发者ID:lazyparser,项目名称:xbot_head,代码行数:13,代码来源:AudioManager.java

示例14: play

import android.media.MediaPlayer; //导入方法依赖的package包/类
/**
 * start playing audio
 *
 * @param uriOrName
 * @param loopTimes
 * @return
 */
public synchronized UDAudio play(String uriOrName, Integer loopTimes) {
    stopAndReset();

    if (uriOrName != null && uriOrName.equals(this.mUriOrName) == false) {//url 不同
        this.mUriOrName = uriOrName;
    }

    if (loopTimes != null) {
        this.mLoopTimes = loopTimes;
    }

    if (this.mUriOrName != null) {
        final MediaPlayer player = getMediaPlayer();
        if (player != null && player.isPlaying() == false) {
            String uri = null;
            boolean assetFileExist = false;
            if (URLUtil.isNetworkUrl(this.mUriOrName) || URLUtil.isFileUrl(this.mUriOrName) || URLUtil.isAssetUrl(this.mUriOrName)) {//net & file & asset
                uri = this.mUriOrName;
            } else {//plain text, use as file path
                uri = getLuaResourceFinder().buildFullPathInBundleOrAssets(this.mUriOrName);
                assetFileExist = AssetUtil.exists(getContext(), uri);
            }
            try {
                if (assetFileExist) {
                    final AssetFileDescriptor descriptor = getContext().getAssets().openFd(uri);
                    player.setDataSource(descriptor.getFileDescriptor(), descriptor.getStartOffset(), descriptor.getLength());
                } else {
                    player.setDataSource(uri);
                }
                player.setOnErrorListener(this);
                player.setOnCompletionListener(this);
                player.setOnPreparedListener(this);
                player.setLooping((this.mLoopTimes != null && this.mLoopTimes > 1) ? true : false);
                player.prepareAsync();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    return this;
}
 
开发者ID:alibaba,项目名称:LuaViewPlayground,代码行数:50,代码来源:UDAudio.java

示例15: onCompletion

import android.media.MediaPlayer; //导入方法依赖的package包/类
@Override
public void onCompletion(MediaPlayer mediaPlayer) {
    if (null!=mPlayer && !mPlayer.isPlaying() && mPlayer.getCurrentPosition()+200>=mPlayer.getDuration()) {
        int musicOrder = mConfigModel.getMusicOrder();
        switch (musicOrder) {
            case CONST.MUSIC_ORDER_SINGLE:
                setCurrentPosition(mPosition);
                if (!mediaPlayer.isPlaying()) {
                    mediaPlayer.start();
                    mHandler.post(new Runnable() {
                        @Override
                        public void run() {
                            if (null != onTrackListener) {
                                onTrackListener.onPlayStateChange(mPlayer.isPlaying());
                            }
                        }
                    });

                }

                break;
            case CONST.MUSIC_ORDER_LIST:
                nextMusic();
                break;
            case CONST.MUSIC_ORDER_RANDOM:
                Random random = new Random();
                int position = random.nextInt(mCurrentPlaylist.size());
                setCurrentPosition(position);
                if (!mediaPlayer.isPlaying()) {
                    mediaPlayer.start();
                }
                mHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        if (null != onTrackListener) {
                            onTrackListener.onPlayStateChange(mPlayer.isPlaying());
                        }
                    }
                });
                break;
        }

    }
}
 
开发者ID:piyell,项目名称:NeteaseCloudMusic,代码行数:45,代码来源:PlayerManager.java


注:本文中的android.media.MediaPlayer.isPlaying方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。