【问题标题】:How to open video, audio and image on secondaryActivity in android如何在android中的辅助Activity上打开视频、音频和图像
【发布时间】:2012-11-07 13:23:55
【问题描述】:

我是 Android 的新学生。我能够从网站获取 xml 以在列表视图中显示文本以及缩略图。我可以使用默认应用程序显示该项目。它主要打开浏览器或媒体 plyaer,但我想在辅助活动中显示应用程序中的内容。它应该从 xml 的标签中检测媒体类型,并使用相关模块/类将其显示在辅助活动中。我不知道如何在内部添加更多活动并打开不同的媒体类型。下面是我现在使用的代码。请指导我记住我是一个完全的新手。提前致谢。

xml 看起来像:

<items count="1">
  <item>
     <title>This is title no 1</title>
     <description>this is description</description>
     <type>mp3, image, video</type>
     <date>date of item</date>
     <thumb>url of an thumbnail</thumb>
     <url>url to play item from</url>
  </item>
</items> 

//listview点击码:

public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
 String title = ((TextView) view.findViewById(R.id.title)).getText().toString();
 String description = ((TextView) view.findViewById(R.id.desc)).getText().toString();
 String type = ((TextView) view.findViewById(R.id.type)).getText().toString();
 String cTime = ((TextView) view.findViewById(R.id.time)).getText().toString();


 Element e = (Element) nl.item(position);  //using final var to get previously declared xmls
 String imageurl = parser.getValue(e, KEY_URL);  
 startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(imageurl))); 
}

【问题讨论】:

    标签: android listview video media internal


    【解决方案1】:

    首先,您需要通过 INTENT API ......它们有助于从一个活动切换到另一个活动......其次,当您尝试播放媒体文件时,Android 操作系统会检测到媒体键入并选择可用的应用程序以从您的设备播放该文件。它会自动从您的应用程序到媒体播放器。前提是您已经完成了对 xml 的解析。如果不存在可以显示您的文件的应用程序,或者说,如果您的设备不支持特定的媒体类型(例如 mp4、wmv、flv 等),则会向您抛出错误,媒体无法播放,因为它不受支持。

    “它主要打开浏览器或媒体 plyaer,但我想在辅助活动中显示应用程序内的内容”

    这是我之前提到的。如果您希望媒体从您的应用程序中播放您的文件,那么您可能应该编写自己的媒体播放器类,您可以将意图传递给该类

    【讨论】:

      猜你喜欢
      • 2014-04-19
      • 2014-07-08
      • 1970-01-01
      • 2013-03-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-09
      • 2019-08-14
      相关资源
      最近更新 更多