为什么我无法使用 Exoplayer 播放 google 驾驶视频?
Why I can not play google drive video using Exoplayer?
我可以在我的 Android 项目中使用 Exoplayer 播放任何 mp4 视频。但是上传到 Google 驱动器或 blogspot 网站的视频没有在 Exoplayer 中播放。这个问题有解决办法吗?
这是我使用的代码:
public class MagicalExoplayer extends AppCompatActivity {
private AndExoPlayerView andExoPlayerView;
// private String TEST_URL_MP4 = "https://www.w3schools.com/html/mov_bbb.mp4";
//Blogger site video link but can't play this video
private String TEST_URL_MP4 = "https://bestmedicalpdf.blogspot.com/2020/05/mrcpwiz-free-mrcp-mcqs-mrcpwiz-your.html";
private String TEST_URL_HLS = "https://content.jwplatform.com/manifests/yp34SRmf.m3u8";
private String TEST_URL_MP3 = "https://host2.rj-mw1.com/media/podcast/mp3-192/Tehranto-41.mp3";
private int req_code = 129;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_magical_exoplayer);
andExoPlayerView = findViewById(R.id.andExoPlayerView);
findViewById(R.id.local).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
selectLocaleVideo();
}
});
findViewById(R.id.mp4).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
loadMP4ServerSide();
}
});
findViewById(R.id.hls).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
loadHls();
}
});
findViewById(R.id.mp3).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
loadMp3();
}
});
}
private void loadMp3() {
andExoPlayerView.setSource(TEST_URL_MP3);
}
private void loadHls() {
andExoPlayerView.setSource(TEST_URL_HLS);
}
private void loadMP4ServerSide() {
andExoPlayerView.setSource(TEST_URL_MP4);
}
private void selectLocaleVideo() {
if (PublicFunctions.checkAccessStoragePermission(this)) {
Intent intent = new Intent();
intent.setType("video/*");
intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Video"), req_code);
}
}
private void loadMP4Locale(String filePath) {
andExoPlayerView.setSource(filePath);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == req_code && resultCode == RESULT_OK) {
Uri finalVideoUri = data.getData();
String filePath = null;
try {
filePath = PathUtil.getPath(this, finalVideoUri);
loadMP4Locale(filePath);
} catch (URISyntaxException e) {
e.printStackTrace();
Toast.makeText(this, "Failed: " + e.getMessage(), Toast.LENGTH_SHORT).show();
}
}
}
private class ChromeClient extends WebChromeClient {
private View mCustomView;
private WebChromeClient.CustomViewCallback mCustomViewCallback;
protected FrameLayout mFullscreenContainer;
private int mOriginalOrientation;
private int mOriginalSystemUiVisibility;
ChromeClient() {
}
public Bitmap getDefaultVideoPoster() {
if (mCustomView == null) {
return null;
}
return BitmapFactory.decodeResource(getApplicationContext().getResources(), 2130837573);
}
public void onHideCustomView() {
((FrameLayout) getWindow().getDecorView()).removeView(this.mCustomView);
this.mCustomView = null;
getWindow().getDecorView().setSystemUiVisibility(this.mOriginalSystemUiVisibility);
setRequestedOrientation(this.mOriginalOrientation);
this.mCustomViewCallback.onCustomViewHidden();
this.mCustomViewCallback = null;
}
public void onShowCustomView(View paramView, WebChromeClient.CustomViewCallback paramCustomViewCallback) {
if (this.mCustomView != null) {
onHideCustomView();
return;
}
this.mCustomView = paramView;
this.mOriginalSystemUiVisibility = getWindow().getDecorView().getSystemUiVisibility();
this.mOriginalOrientation = getRequestedOrientation();
this.mCustomViewCallback = paramCustomViewCallback;
((FrameLayout) getWindow().getDecorView()).addView(this.mCustomView, new FrameLayout.LayoutParams(-1, -1));
getWindow().getDecorView().setSystemUiVisibility(3846 | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
}
}
但任何其他 mp4 视频都可以轻松播放。
https://bestmedicalpdf.blogspot.com/2020/05/mrcpwiz-free-mrcp-mcqs-mrcpwiz-your.html 是网页,而不是 url 视频或音频文件。
我可以在我的 Android 项目中使用 Exoplayer 播放任何 mp4 视频。但是上传到 Google 驱动器或 blogspot 网站的视频没有在 Exoplayer 中播放。这个问题有解决办法吗?
这是我使用的代码:
public class MagicalExoplayer extends AppCompatActivity {
private AndExoPlayerView andExoPlayerView;
// private String TEST_URL_MP4 = "https://www.w3schools.com/html/mov_bbb.mp4";
//Blogger site video link but can't play this video
private String TEST_URL_MP4 = "https://bestmedicalpdf.blogspot.com/2020/05/mrcpwiz-free-mrcp-mcqs-mrcpwiz-your.html";
private String TEST_URL_HLS = "https://content.jwplatform.com/manifests/yp34SRmf.m3u8";
private String TEST_URL_MP3 = "https://host2.rj-mw1.com/media/podcast/mp3-192/Tehranto-41.mp3";
private int req_code = 129;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_magical_exoplayer);
andExoPlayerView = findViewById(R.id.andExoPlayerView);
findViewById(R.id.local).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
selectLocaleVideo();
}
});
findViewById(R.id.mp4).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
loadMP4ServerSide();
}
});
findViewById(R.id.hls).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
loadHls();
}
});
findViewById(R.id.mp3).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
loadMp3();
}
});
}
private void loadMp3() {
andExoPlayerView.setSource(TEST_URL_MP3);
}
private void loadHls() {
andExoPlayerView.setSource(TEST_URL_HLS);
}
private void loadMP4ServerSide() {
andExoPlayerView.setSource(TEST_URL_MP4);
}
private void selectLocaleVideo() {
if (PublicFunctions.checkAccessStoragePermission(this)) {
Intent intent = new Intent();
intent.setType("video/*");
intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Video"), req_code);
}
}
private void loadMP4Locale(String filePath) {
andExoPlayerView.setSource(filePath);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == req_code && resultCode == RESULT_OK) {
Uri finalVideoUri = data.getData();
String filePath = null;
try {
filePath = PathUtil.getPath(this, finalVideoUri);
loadMP4Locale(filePath);
} catch (URISyntaxException e) {
e.printStackTrace();
Toast.makeText(this, "Failed: " + e.getMessage(), Toast.LENGTH_SHORT).show();
}
}
}
private class ChromeClient extends WebChromeClient {
private View mCustomView;
private WebChromeClient.CustomViewCallback mCustomViewCallback;
protected FrameLayout mFullscreenContainer;
private int mOriginalOrientation;
private int mOriginalSystemUiVisibility;
ChromeClient() {
}
public Bitmap getDefaultVideoPoster() {
if (mCustomView == null) {
return null;
}
return BitmapFactory.decodeResource(getApplicationContext().getResources(), 2130837573);
}
public void onHideCustomView() {
((FrameLayout) getWindow().getDecorView()).removeView(this.mCustomView);
this.mCustomView = null;
getWindow().getDecorView().setSystemUiVisibility(this.mOriginalSystemUiVisibility);
setRequestedOrientation(this.mOriginalOrientation);
this.mCustomViewCallback.onCustomViewHidden();
this.mCustomViewCallback = null;
}
public void onShowCustomView(View paramView, WebChromeClient.CustomViewCallback paramCustomViewCallback) {
if (this.mCustomView != null) {
onHideCustomView();
return;
}
this.mCustomView = paramView;
this.mOriginalSystemUiVisibility = getWindow().getDecorView().getSystemUiVisibility();
this.mOriginalOrientation = getRequestedOrientation();
this.mCustomViewCallback = paramCustomViewCallback;
((FrameLayout) getWindow().getDecorView()).addView(this.mCustomView, new FrameLayout.LayoutParams(-1, -1));
getWindow().getDecorView().setSystemUiVisibility(3846 | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
}
}
但任何其他 mp4 视频都可以轻松播放。
https://bestmedicalpdf.blogspot.com/2020/05/mrcpwiz-free-mrcp-mcqs-mrcpwiz-your.html 是网页,而不是 url 视频或音频文件。