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


Java AssetFileDescriptor.close方法代码示例

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


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

示例1: getDuration

import android.content.res.AssetFileDescriptor; //导入方法依赖的package包/类
public static int getDuration(MediaPlayer mediaPlayer, AssetFileDescriptor afd) {
    int duration = 500;

    try {
        mediaPlayer.reset();
        mediaPlayer.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength());
        afd.close();
        mediaPlayer.prepare();
        duration = mediaPlayer.getDuration();
    } catch(IOException e) {
        Log.e(TAG, e.toString());
    }

    mediaPlayer.reset();

    return duration;
}
 
开发者ID:Samsung,项目名称:microbit,代码行数:18,代码来源:AlertPlugin.java

示例2: buildMediaPlayer

import android.content.res.AssetFileDescriptor; //导入方法依赖的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:amap-demo,项目名称:weex-3d-map,代码行数:22,代码来源:BeepManager.java

示例3: buildMediaPlayer

import android.content.res.AssetFileDescriptor; //导入方法依赖的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:xiong-it,项目名称:ZXingAndroidExt,代码行数:22,代码来源:BeepManager.java

示例4: buildMediaPlayer

import android.content.res.AssetFileDescriptor; //导入方法依赖的package包/类
private MediaPlayer buildMediaPlayer(Context activity) {
  MediaPlayer mediaPlayer = new MediaPlayer();
  try {
    AssetFileDescriptor file = activity.getResources().openRawResourceFd(this.rawBeep);
    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:10045125,项目名称:QrCode,代码行数:22,代码来源:BeepManager.java

示例5: initBeepSound

import android.content.res.AssetFileDescriptor; //导入方法依赖的package包/类
private void initBeepSound() {
    this.playBeep = true;
    if (((AudioManager) getSystemService("audio")).getRingerMode() != 2) {
        this.playBeep = false;
    }
    if (this.playBeep && this.mediaPlayer == null) {
        setVolumeControlStream(3);
        this.mediaPlayer = new MediaPlayer();
        this.mediaPlayer.setAudioStreamType(3);
        this.mediaPlayer.setOnCompletionListener(this.beepListener);
        AssetFileDescriptor file = getResources().openRawResourceFd(R.raw.beep);
        try {
            this.mediaPlayer.setDataSource(file.getFileDescriptor(), file.getStartOffset(), file.getLength());
            file.close();
            this.mediaPlayer.setVolume(BEEP_VOLUME, BEEP_VOLUME);
            this.mediaPlayer.prepare();
        } catch (IOException e) {
            this.mediaPlayer = null;
        }
    }
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:22,代码来源:SweepActivity.java

示例6: enableMediaPlayer

import android.content.res.AssetFileDescriptor; //导入方法依赖的package包/类
private void enableMediaPlayer() {
	mediaPlayer = new MediaPlayer();

	float volume = prefs.getFloat(PreferenceConstants.BELL_VOLUME,
			PreferenceConstants.DEFAULT_BELL_VOLUME);

	mediaPlayer.setAudioStreamType(AudioManager.STREAM_NOTIFICATION);

	AssetFileDescriptor file = res.openRawResourceFd(R.raw.bell);
	try {
		mediaPlayer.setLooping(false);
		mediaPlayer.setDataSource(file.getFileDescriptor(), file
				.getStartOffset(), file.getLength());
		file.close();
		mediaPlayer.setVolume(volume, volume);
		mediaPlayer.prepare();
	} catch (IOException e) {
		Log.e(TAG, "Error setting up bell media player", e);
	}
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:21,代码来源:TerminalManager.java

示例7: buildMediaPlayer

import android.content.res.AssetFileDescriptor; //导入方法依赖的package包/类
private MediaPlayer buildMediaPlayer(Context activity,modes mode) {
  MediaPlayer mediaPlayer = new MediaPlayer();
  mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
  mediaPlayer.setOnCompletionListener(this);
  mediaPlayer.setOnErrorListener(this);
  try {
    AssetFileDescriptor file;
    if(mode==modes.SINGLE)
      file = activity.getResources().openRawResourceFd(R.raw.beep);
    else
      file = activity.getResources().openRawResourceFd(R.raw.triplebeep);
    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:crisfg86,项目名称:Zxing-Custom,代码行数:26,代码来源:BeepManager.java

示例8: buildMediaPlayer

import android.content.res.AssetFileDescriptor; //导入方法依赖的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:TonnyL,项目名称:Espresso,代码行数:22,代码来源:BeepManager.java

示例9: buildMediaPlayer

import android.content.res.AssetFileDescriptor; //导入方法依赖的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:Hultron,项目名称:LifeHelper,代码行数:22,代码来源:BeepManager.java

示例10: buildMediaPlayer

import android.content.res.AssetFileDescriptor; //导入方法依赖的package包/类
private static MediaPlayer buildMediaPlayer(Context activity) {
    MediaPlayer mediaPlayer = new MediaPlayer();
    mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    // When the beep has finished playing, rewind to queue up another one.
    mediaPlayer
            .setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
                @Override
                public void onCompletion(MediaPlayer player) {
                    player.seekTo(0);
                }
            });

    AssetFileDescriptor file = activity.getResources().openRawResourceFd(
            R.raw.baidu_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:angcyo,项目名称:RLibrary,代码行数:27,代码来源:BeepManager.java

示例11: loadFallbackResource

import android.content.res.AssetFileDescriptor; //导入方法依赖的package包/类
/**
 * Returns a file address from a resource, or null if it cannot be opened.
 */
public static AssetFileAddress loadFallbackResource(final Context context,
        final int fallbackResId) {
    AssetFileDescriptor afd = null;
    try {
        afd = context.getResources().openRawResourceFd(fallbackResId);
    } catch (RuntimeException e) {
        Log.e(TAG, "Resource not found: " + fallbackResId);
        return null;
    }
    if (afd == null) {
        Log.e(TAG, "Resource cannot be opened: " + fallbackResId);
        return null;
    }
    try {
        return AssetFileAddress.makeFromFileNameAndOffset(
                context.getApplicationInfo().sourceDir, afd.getStartOffset(), afd.getLength());
    } finally {
        try {
            afd.close();
        } catch (IOException ignored) {
        }
    }
}
 
开发者ID:sergeychilingaryan,项目名称:AOSP-Kayboard-7.1.2,代码行数:27,代码来源:BinaryDictionaryGetter.java

示例12: playAssetsFile

import android.content.res.AssetFileDescriptor; //导入方法依赖的package包/类
/**
 * 播放音频文件
 *
 * @param file
 * @param repeat
 */
private void playAssetsFile(String file, boolean repeat) {
    try {
        Log.i(TAG, "file:" + file);
        currentFile = file;
        AssetFileDescriptor fd = mAssetManager.openFd(file);
        mPlayer.reset();
        mPlayer.setDataSource(fd.getFileDescriptor(), fd.getStartOffset(), fd.getLength());
        mPlayer.setAudioStreamType(mediator.isBlueToothHeadSet() ? AudioManager.STREAM_VOICE_CALL : AudioManager.STREAM_MUSIC);
        mPlayer.setLooping(repeat);
        mPlayer.prepareAsync();
        fd.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:LingjuAI,项目名称:AssistantBySDK,代码行数:22,代码来源:SpeechPlayer.java

示例13: startBgm

import android.content.res.AssetFileDescriptor; //导入方法依赖的package包/类
public void startBgm(Context context, String name) {
    try {
        bgmPlayer.reset();
        path = "sport_audio/" + name + VideoDownloadHelper.AUDIO_FORMAT;
        AssetFileDescriptor descriptor = context.getAssets().openFd(path);
        bgmPlayer.setDataSource(descriptor.getFileDescriptor(), descriptor.getStartOffset(),
                descriptor.getLength());
        descriptor.close();
        bgmPlayer.prepare();
        bgmPlayer.start();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (IllegalStateException e2) {
        e2.printStackTrace();
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:17,代码来源:BGMPlayerManager.java

示例14: buildMediaPlayer

import android.content.res.AssetFileDescriptor; //导入方法依赖的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:hsj-xiaokang,项目名称:OSchina_resources_android,代码行数:22,代码来源:BeepManager.java

示例15: buildMediaPlayer

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


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