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


Java MediaPlayer.setAudioStreamType方法代码示例

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


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

示例1: playVideo

import android.media.MediaPlayer; //导入方法依赖的package包/类
private void playVideo(Integer Media) {
    doCleanUp();
    try {
        // Create a new media player and set the listeners
        mMediaPlayer = new MediaPlayer();
        mMediaPlayer.setDataSource(path);
        mMediaPlayer.setDisplay(holder);
        mMediaPlayer.prepareAsync();
        mMediaPlayer.setOnBufferingUpdateListener(this);
        mMediaPlayer.setOnCompletionListener(this);
        mMediaPlayer.setOnPreparedListener(this);
        mMediaPlayer.setOnVideoSizeChangedListener(this);
        mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    } catch (Exception e) {
        Log.e(TAG, "error: " + e.getMessage(), e);
    }
}
 
开发者ID:narenkukreja,项目名称:quire,代码行数:18,代码来源:MediaPlayerActivity.java

示例2: buildMediaPlayer

import android.media.MediaPlayer; //导入方法依赖的package包/类
private MediaPlayer buildMediaPlayer(Context activity) {
    MediaPlayer mediaPlayer = new MediaPlayer();
    mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    mediaPlayer.setOnCompletionListener(this);
    mediaPlayer.setOnErrorListener(this);
    try {
        AssetFileDescriptor file = activity.getResources().openRawResourceFd(R.raw.beep);
        try {
            mediaPlayer.setDataSource(file.getFileDescriptor(), file.getStartOffset(), file.getLength());
        } finally {
            file.close();
        }
        mediaPlayer.setVolume(BEEP_VOLUME, BEEP_VOLUME);
        mediaPlayer.prepare();
        return mediaPlayer;
    } catch (IOException ioe) {
        Log.w(TAG, ioe);
        mediaPlayer.release();
        return null;
    }
}
 
开发者ID:alibaba,项目名称:LuaViewPlayground,代码行数:22,代码来源:BeepManager.java

示例3: buildMediaPlayer

import android.media.MediaPlayer; //导入方法依赖的package包/类
private MediaPlayer buildMediaPlayer(Context activity) {
    MediaPlayer mediaPlayer = new MediaPlayer();
    mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    mediaPlayer.setOnCompletionListener(this);
    mediaPlayer.setOnErrorListener(this);
    try {
        AssetFileDescriptor file = activity.getResources().openRawResourceFd(R.raw.qr_sacn);
        try {
            mediaPlayer.setDataSource(file.getFileDescriptor(), file.getStartOffset(), file.getLength());
        } finally {
            file.close();
        }
        mediaPlayer.setVolume(BEEP_VOLUME, BEEP_VOLUME);
        mediaPlayer.prepare();
        return mediaPlayer;
    } catch (IOException ioe) {
        Log.w(TAG, ioe);
        mediaPlayer.release();
        return null;
    }
}
 
开发者ID:coding-dream,项目名称:TPlayer,代码行数:22,代码来源:BeepManager.java

示例4: createPlayer

import android.media.MediaPlayer; //导入方法依赖的package包/类
private MediaPlayer createPlayer() {
  try {
    MediaPlayer mediaPlayer = new MediaPlayer();
    Uri         ringtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);

    mediaPlayer.setOnErrorListener(new MediaPlayerErrorListener());
    mediaPlayer.setDataSource(context, ringtoneUri);
    mediaPlayer.setLooping(true);
    mediaPlayer.setAudioStreamType(AudioManager.STREAM_RING);

    return mediaPlayer;
  } catch (IOException e) {
    Log.e(TAG, "Failed to create player for incoming call ringer");
    return null;
  }
}
 
开发者ID:CableIM,项目名称:Cable-Android,代码行数:17,代码来源:IncomingRinger.java

示例5: buildMediaPlayer

import android.media.MediaPlayer; //导入方法依赖的package包/类
private MediaPlayer buildMediaPlayer(Context activity) {
  MediaPlayer mediaPlayer = new MediaPlayer();
  mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
  mediaPlayer.setOnCompletionListener(this);
  mediaPlayer.setOnErrorListener(this);

  AssetFileDescriptor file = activity.getResources().openRawResourceFd(keepass2android.plugin.qr.R.raw.beep);
  try {
    mediaPlayer.setDataSource(file.getFileDescriptor(), file.getStartOffset(), file.getLength());
    file.close();
    mediaPlayer.setVolume(BEEP_VOLUME, BEEP_VOLUME);
    mediaPlayer.prepare();
  } catch (IOException ioe) {
    Log.w(TAG, ioe);
    mediaPlayer = null;
  }
  return mediaPlayer;
}
 
开发者ID:PhilippC,项目名称:keepass2android,代码行数:19,代码来源:BeepManager.java

示例6: buildMediaPlayer

import android.media.MediaPlayer; //导入方法依赖的package包/类
private MediaPlayer buildMediaPlayer(Context activity) {
  MediaPlayer mediaPlayer = new MediaPlayer();
  try {
    AssetFileDescriptor file = activity.getResources().openRawResourceFd(R.raw.beep);
    try {
      mediaPlayer.setDataSource(file.getFileDescriptor(), file.getStartOffset(), file.getLength());
    } finally {
      file.close();
    }
    mediaPlayer.setOnErrorListener(this);
    mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    mediaPlayer.setLooping(false);
    mediaPlayer.setVolume(BEEP_VOLUME, BEEP_VOLUME);
    mediaPlayer.prepare();
    return mediaPlayer;
  } catch (IOException ioe) {
    Log.w(TAG, ioe);
    mediaPlayer.release();
    return null;
  }
}
 
开发者ID:kkyflying,项目名称:CodeScaner,代码行数:22,代码来源:BeepManager.java

示例7: buildMediaPlayer

import android.media.MediaPlayer; //导入方法依赖的package包/类
private MediaPlayer buildMediaPlayer(Context activity) {
    mediaPlayer = new MediaPlayer();
    mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    mediaPlayer.setOnCompletionListener(this);
    // mediaPlayer.setOnErrorListener(this);
    try {
        AssetFileDescriptor file = activity.getResources()
                .openRawResourceFd(R.raw.beep);
        try {
            mediaPlayer.setDataSource(file.getFileDescriptor(),
                    file.getStartOffset(), file.getLength());
        } finally {
            file.close();
        }
        mediaPlayer.setVolume(0.10f, 0.10f);
        mediaPlayer.prepare();
        return mediaPlayer;
    } catch (IOException ioe) {
        mediaPlayer.release();
        return null;
    }
}
 
开发者ID:c3cashdesk,项目名称:postixdroid,代码行数:23,代码来源:MainActivity.java

示例8: createPlayer

import android.media.MediaPlayer; //导入方法依赖的package包/类
private MediaPlayer createPlayer() {
    try {
        MediaPlayer mediaPlayer = new MediaPlayer();
        Uri         ringtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);

        mediaPlayer.setOnErrorListener(new MediaPlayerErrorListener());
        mediaPlayer.setDataSource(context, ringtoneUri);
        mediaPlayer.setLooping(true);
        mediaPlayer.setAudioStreamType(AudioManager.STREAM_VOICE_CALL);

        return mediaPlayer;
    } catch (IOException e) {
        Log.e(TAG, "Failed to create player for incoming call ringer");
        return null;
    }
}
 
开发者ID:XecureIT,项目名称:PeSanKita-android,代码行数:17,代码来源:IncomingRinger.java

示例9: buildMediaPlayer

import android.media.MediaPlayer; //导入方法依赖的package包/类
private MediaPlayer buildMediaPlayer(Context activity) {
	MediaPlayer mediaPlayer = new MediaPlayer();
	mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
	mediaPlayer.setOnCompletionListener(this);
	mediaPlayer.setOnErrorListener(this);

	AssetFileDescriptor file = activity.getResources().openRawResourceFd(R.raw.beep);
	try {
		mediaPlayer.setDataSource(file.getFileDescriptor(),
				file.getStartOffset(), file.getLength());
		file.close();
		mediaPlayer.setVolume(BEEP_VOLUME, BEEP_VOLUME);
		mediaPlayer.prepare();
	} catch (IOException ioe) {
		Log.w(TAG, ioe);
		mediaPlayer = null;
	}
	return mediaPlayer;
}
 
开发者ID:dufangyu1990,项目名称:LeCatApp,代码行数:20,代码来源:BeepManager.java

示例10: playProgressTone

import android.media.MediaPlayer; //导入方法依赖的package包/类
public void playProgressTone() {
    mPlayer = new MediaPlayer();
    mPlayer.setAudioStreamType(AudioManager.STREAM_RING);
    int maxVolume = 100;
    final float volume = (float) (1 - (Math.log(maxVolume - 1) / Math.log(maxVolume)));
    mPlayer.setVolume(volume, volume);

    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();
}
 
开发者ID:squareboat,项目名称:Excuser,代码行数:19,代码来源:AudioPlayer.java

示例11: onCreate

import android.media.MediaPlayer; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    //initializing button
    btn = findViewById(R.id.play);

    //initializing mediaPlayer object
    mediaPlayer = new MediaPlayer();

    //setting streaming type
    mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);

    //setting clickListener on button
    btn.setOnClickListener(pausePlay);

}
 
开发者ID:stoic1979,项目名称:DroidStreamingDemo,代码行数:19,代码来源:MainActivity.java

示例12: initAudioPlayer

import android.media.MediaPlayer; //导入方法依赖的package包/类
private void initAudioPlayer() throws IOException {
        audioPlay = new MediaPlayer();
//        audioPlay.setOnPreparedListener(prepareListener);
        audioPlay.setOnCompletionListener(endAudioListener);
        audioPlay.setAudioStreamType(AudioManager.STREAM_MUSIC);
        audioPlay.setDataSource(audioFilePath);
        audioPlay.prepare();
    }
 
开发者ID:gvsucis,项目名称:mobile-app-dev-book,代码行数:9,代码来源:AudioActivity.java

示例13: AndroidMediaPlayer

import android.media.MediaPlayer; //导入方法依赖的package包/类
public AndroidMediaPlayer() {
    synchronized (mInitLock) {
        mInternalMediaPlayer = new MediaPlayer();
    }
    mInternalMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    mInternalListenerAdapter = new AndroidMediaPlayerListenerHolder(this);
    attachInternalListeners();
}
 
开发者ID:bigjelly,项目名称:ShaddockVideoPlayer,代码行数:9,代码来源:AndroidMediaPlayer.java

示例14: blastTheAlarm

import android.media.MediaPlayer; //导入方法依赖的package包/类
private void blastTheAlarm(String mediaUrl) {
    mMediaPlayer = new MediaPlayer();
    mMediaPlayer.setAudioStreamType(AudioManager.STREAM_ALARM);

    try {
        mMediaPlayer.setDataSource(mediaUrl);
    } catch (IOException e) {
        Log.e(TAG, String.format("Error playing media from URL: %s", mediaUrl));
    }

    setAlarmToMaxVolume();
    mMediaPlayer.prepareAsync();
    mMediaPlayer.setOnPreparedListener(mp -> mMediaPlayer.start());
}
 
开发者ID:KevinLiddle,项目名称:crockpod,代码行数:15,代码来源:AlarmRingingActivity.java

示例15: toggle

import android.media.MediaPlayer; //导入方法依赖的package包/类
public boolean toggle(int id, VoiceMessage audio) throws PrepareException {
    if (Objects.nonNull(mPlayingEntry) && mPlayingEntry.getId() == id) {
        setSupposedToPlay(!isSupposedToPlay());
        return false;
    }

    stop();

    mPlayingEntry = new AudioEntry(id, audio);
    mDuration = audio.getDuration() * 1000;
    mPlayer = new MediaPlayer();

    try {
        mPlayer.setDataSource(mPlayingEntry.getAudio().getLinkMp3());
    } catch (IOException e) {
        throw new PrepareException();
    }

    mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    mPlayer.setOnPreparedListener(this);
    mPlayer.setOnErrorListener(this);
    mPlayer.setOnCompletionListener(this);

    mSupposedToPlay = true;
    changeStatusTo(STATUS_PREPARING);

    mPlayer.prepareAsync();
    return true;
}
 
开发者ID:PhoenixDevTeam,项目名称:Phoenix-for-VK,代码行数:30,代码来源:DefaultVoicePlayer.java


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