[英]mp4 video cannot be played in Android VideoView and Mediaplayer
I have indeed tried to check here and else were for solution to this but no luck, probably because am a newbee. 我确实曾尝试在这里进行检查,否则正在寻求解决方案,但没有运气,可能是因为它是新手。
TASK: I want to play a RTSP
video stream on an android app
任务:我想在
android app
上播放RTSP
视频流
TRIALS: I tried out with a 2min mp4
video copied to the res\\raw
folder with Media Player and VideoView
. 试用:我尝试使用Media Player和
VideoView
将2min mp4
视频复制到res\\raw
文件夹中。 Later I used the API Demo
sample and I set: 后来,我使用了
API Demo
示例,并进行了设置:
path = "android.resourcee://com.me.mobile/R.raw.mithlat";
ERROR: on MediaPlayer
API Demo just a blank page, no video no sound on VideoView
API Demo it shows 错误:在
MediaPlayer
API演示上只是空白页,在显示的VideoView
API演示上没有视频没有声音
"Sorry this video cannot be played"
CONFIG: My target is 2.33
(This is what am testing with) CONFIG:我的目标是
2.33
(正在测试中)
minimun is 2.1
Thank you 谢谢
Video Streaming or Playing Video require too much power. 视频流或播放视频需要太多功率。 Sometimes it will not play to emulator.
有时它不会在模拟器上播放。 try to Run it to your phone.
尝试将其运行到手机上。
Try this code and Run this to your phone. 尝试使用此代码,然后将其运行到手机上。
public void onCreate(Bundle savedInstanceState){
setContentView(R.layout.main);
String videourl = "http://something.com/blah.mp4";
Uri uri = Uri.parse(videourl);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
intent.setDataAndType(uri, "video/mp4");
startActivity(intent);
}
Or Click here to watch Android Video Streaming Tutorial . 或单击此处观看Android视频流教程 。
I know it a very late reply but for future references, I am adding this. 我知道这是一个很晚的答复,但是为了将来参考,我将其添加。
This is because path should be mentioned like this : "android.resource://" + getPackageName() +"/raw/" + mediaName"
, where media name is the name of video sample. 这是因为应该这样提及路径:
"android.resource://" + getPackageName() +"/raw/" + mediaName"
,其中媒体名称是视频样本的名称。
R.raw.variableName/fileName
gives the int value references and should be with the Android's inbuilt functions like getString(R.id.string_name)
, which return the exact resources in required formats. R.raw.variableName/fileName
提供int值引用,并且应与Android的内置函数(如getString(R.id.string_name)
,该函数以要求的格式返回确切的资源。
Also, in this case, VideoView
is not getting the proper media file that's why it is not able to run it and giving this error. 同样,在这种情况下,
VideoView
无法获取正确的媒体文件,这就是为什么它无法运行并给出此错误的原因。
Try the stream rtsp://184.72.239.149/vod/mp4:BigBuckBunny_115k.mov. 尝试流rtsp://184.72.239.149/vod/mp4:BigBuckBunny_115k.mov。 Type this in your browser and it will automatically open with the android native player.
在您的浏览器中键入此内容,它将自动使用android native player打开。 If this plays then you probably need to look at your stream once again.
如果播放了,那么您可能需要再次查看流。 I dont have android 2.3 although i played the same url in android 3.2 and it worked.
我没有android 2.3,尽管我在android 3.2中播放了相同的url,但仍然有效。 Also check the answer of Playing a video in VideoView in Android for you reference.
另请检查在Android的VideoView中播放视频的答案, 以供参考。 Hope this helps you I guess android 2.3 does not support
rtsp
although not pretty sure. 希望这对您
rtsp
帮助,我猜android 2.3虽然不太确定,但不支持rtsp
。 Try the url and check if it is playing 尝试url并检查它是否正在播放
Please try the following code for playing Video in the videoView 请尝试以下代码在videoView中播放视频
VideoView videoView = (VideoView)findViewById(R.id.VideoView);
Uri uri = Uri.parse("android.resource://" + getPackageName()+"/"+ R.raw.demo7);
video.setVideoURI(uri);
video.start();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.