英文:
AdroidStudio: trying to play a mp4 but it keeps displaying as a text file
问题
I'm not sure whats going on. I'm just tying to run a simple one min video through android studio and for some reason when the file gets called it just craps out.
Here is my mainActivity I dont see any problems with it
package com.example.videodemo;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.VideoView;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
VideoView videoView = (VideoView) findViewById(R.id.videoView);
videoView.setVideoPath("android.resource://" + getPackageName() + "/" + R.raw.introVid);
videoView.start();
}
}
Here is what I'm seeing happen to my mp4 file when trying to run the app
I'm not sure whats going on I even restarted androidStudio after invalidating caches and still have the same problem
英文:
I'm not sure whats going on. I'm just tying to run a simple one min video through android studio and for some reason when the file gets called it just craps out.
Here is my mainActivity I dont see any problems with it
package com.example.videodemo;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.VideoView;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
VideoView videoView = (VideoView) findViewById(R.id.videoView);
videoView.setVideoPath("android.resource://" + getPackageName() + "/" + R.raw.introVid);
videoView.start();
}
}
Here is what I'm seeing happen to my mp4 file when trying to run the app
I'm not sure whats going on I even restarted androidStudio after invalidating caches and still have the same problem
答案1
得分: 1
所以事实证明,(必须仅包含小写a-z,0-9)也适用于视频资源。
英文:
So turns out the (must contain only lowercase a-z, 0-9) goes for the video resource as well.
答案2
得分: 0
使用Uri代替Path
VideoView videoView = (VideoView) findViewById(R.id.videoView);
videoView.setVideoUri(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.introVid)); // 尝试这段代码
videoView.start();
英文:
Use Uri instead of Path
VideoView videoView = (VideoView) findViewById(R.id.videoView);
videoView.setVideoUri(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.introVid)); // try this code
videoView.start();
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论