我正在使用AssetFileDescriptor通过调用放置在应用程序raw / assets文件夹中的getStartOffset来获取StartOffset。
对于不存在于资产/原始文件夹中的文件,如何使用File对象获得类似的startOffset?但可以在应用商店中下载并有一个文件对象。
AssetFileDescriptor fd0 = getResources().openRawResourceFd(R.raw.lycka);
AssetFileDescriptor fd1 = getResources().openRawResourceFd(R.raw.nuyorica);
fileAoffset = (int)fd0.getStartOffset();
fileAlength = (int)fd0.getLength();
fileBoffset = (int)fd1.getStartOffset();
fileBlength = (int)fd1.getLength();
File file = new File("data/user/0/com.myapp.com/files/audio/-LGHK12NDo83k9pHakIZ.m4a");
long fileLen = file.length();
// i want startOffset from File object as getting in AssetFileDescriptor
答案 0 :(得分:0)
如果要使用文件路径启动偏移,可以使用以下代码
public class CustomPageTransformer implements ViewPager.PageTransformer {
public void transformPage(View view, float position) {
int pageWidth = view.getWidth();
View imageView = view.findViewById(R.id.image_view);
View contentView = view.findViewById(R.id.content_area);
if (position < -1) { // [-Infinity,-1)
// This page is way off-screen to the left
} else if (position <= 0) { // [-1,0]
// This page is moving out to the left
// Counteract the default swipe
view.setTranslationX(pageWidth * -position);
if (contentView != null) {
// But swipe the contentView
contentView.setTranslationX(pageWidth * position);
}
if (imageView != null) {
// Fade the image in
imageView.setAlpha(1 + position);
}
} else if (position <= 1) { // (0,1]
// This page is moving in from the right
// Counteract the default swipe
view.setTranslationX(pageWidth * -position);
if (contentView != null) {
// But swipe the contentView
contentView.setTranslationX(pageWidth * position);
}
if (imageView != null) {
// Fade the image out
imageView.setAlpha(1 - position);
}
} else { // (1,+Infinity]
// This page is way off-screen to the right
}
}