Android Studio:尝试播放一个MP4文件,但它一直显示为文本文件。

huangapple go评论97阅读模式
英文:

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

Android Studio:尝试播放一个MP4文件,但它一直显示为文本文件。

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

Android Studio:尝试播放一个MP4文件,但它一直显示为文本文件。

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();

huangapple
  • 本文由 发表于 2020年9月14日 20:24:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/63884286.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定