Android 媒体播放器不工作

发布于 2024-11-10 15:12:36 字数 1988 浏览 6 评论 0原文

我正在尝试开发一个嵌入了许多视频的应用程序,我想调用Android的媒体播放器,并将视频放在VideoView对象上。但是,我收到这些奇怪的错误:

  • I/MediaPlayer( 2874): Info (1,26)
  • E/MediaPlayer( 2874): Error (-4,-4)
  • D/VideoView( 2874): Error: -4,-4

当我尝试播放 mp4 视频或其他不是从我的手机录制的 3gp 视频时。我的代码是这样的:

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.MediaController;
import android.widget.VideoView;

public class PlayTest2 extends Activity{
private MediaController ctlr;
public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.test2);

    try {
        VideoView video = (VideoView) findViewById(R.id.test2);
        // Load and start the movie
                video.setVideoPath("android.resource://com.example.child.protector/raw/output");
        ctlr=new MediaController(this);
        ctlr.setMediaPlayer(video);
        video.setMediaController(ctlr);
        video.start();
        //video.requestFocus();//this line is new
    }
    catch (Exception e) {
       Log.e("---------- this is my app --------", "error: " + e.getMessage(), e);

    }
}
}

我的布局是这样的:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<VideoView
android:id="@+id/test2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
/>
</FrameLayout>

我的代码有问题吗?

我知道我的文件就在那里。我已经使用示例 3GP 视频运行了此代码,效果很好(但我从手机录制了视频并将其复制到我的计算机,然后重新打包到我的应用程序中,位于 Eclipse 中的 /res/raw 文件夹下)。然而,问题是由于某种原因,我的媒体播放器只能播放某些 3GPP 文件。如果我尝试使用 MobileMediaConverter 将 MP4 转换为 3GP,它可以在我的笔记本电脑上播放,但不能在此应用程序中播放。另请注意,如果我将视频作为文件打开(换句话说,调用我的三星 Galaxy S 手机上的默认视频播放器),它就可以正常工作(这意味着我的手机具有该功能)。所以我想知道:

  • 代码有问题吗?
  • 这更像是将 mp4 转换为 3gp 错误吗?

任何帮助将不胜感激。谢谢!!

I'm trying to develop an app that has many videos embedded in it, and I'd like to call Android's Media Player, with the video on VideoView object. However, i get these strange errors:

  • I/MediaPlayer( 2874): Info (1,26)
  • E/MediaPlayer( 2874): Error (-4,-4)
  • D/VideoView( 2874): Error: -4,-4

when i try to play a mp4 video, or another 3gp video that is not recorded from my phone. My code is something like:

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.MediaController;
import android.widget.VideoView;

public class PlayTest2 extends Activity{
private MediaController ctlr;
public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.test2);

    try {
        VideoView video = (VideoView) findViewById(R.id.test2);
        // Load and start the movie
                video.setVideoPath("android.resource://com.example.child.protector/raw/output");
        ctlr=new MediaController(this);
        ctlr.setMediaPlayer(video);
        video.setMediaController(ctlr);
        video.start();
        //video.requestFocus();//this line is new
    }
    catch (Exception e) {
       Log.e("---------- this is my app --------", "error: " + e.getMessage(), e);

    }
}
}

and my layout is something like:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<VideoView
android:id="@+id/test2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
/>
</FrameLayout>

Is there something wrong with my code?

and i know that my file is there and all. I've run this code with a sample 3GP video and it worked just fine (but i recorded the video from my phone and copied it to my computer and then re-packaged in to my app, under the /res/raw folder in Eclipse). However, The problem is that for some reason, my media player only plays certain 3GPP files. If i try to convert a MP4 to 3GP using MobileMediaConverter, it plays on my laptop but not in this app. Also note that if i open the video as a file (in other words, invoking the default video player on my Samsung Galaxy S phone) it works just fine (meaning my phone has the capabilities). So i'm wondering:

  • is this something wrong with the code?
  • is this more of a converting mp4 to 3gp error?

Any help would be greatly appreciated. Thanks!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

雅心素梦 2024-11-17 15:12:36

问题是某些转换器(具有不同的设置)将创建一个无法在我的 Samsung Galaxy Android 设备上运行的视频文件。这里的代码是通用的,但我认为在进行视频转换时编解码器必须类似于 H.264。然后我下载了大约 5 个视频转换器,其中 2 个实际上可以制作我的设备可以播放的 3GPP。因此,如果其他人遇到此问题,我建议尝试使用不同的编解码器/音频设置的一堆视频转换器。我最终找到了适合我的特定情况的一个

The problem was the certain converters (with different settings) will create a video file that doesn't run on my Samsung Galaxy android device. the code here is generic, but i think the codec has to be something like H.264 when doing the video conversion. I then downloaded about 5 video converters and 2 of them will actually make a 3GPP that my device can play. so if anyone else has this problem, i would recommend trying a bunch of video converters, with different codec/audio settings. i was eventually able to find one that worked in my particular case

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文