- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
我创建了一个自定义的 VideoView 类,它扩展了 VideoView 并声明了三个构造函数:
package com.tibo.webtv;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import org.apache.http.conn.ConnectTimeoutException;
import com.framework.utilityframe.log.log;
import com.framework.utilityframe.utility.utility;
import com.tibo.webtv.activities.PlayerActivity;
import com.tibo.webtv.database.objects.ServerResponseObject;
import com.tibo.webtv.database.objects.TVChannelObject;
import com.tibo.webtv.global.Global;
import com.tibo.webtv.util.TiboCacheKey;
import com.tibo.webtv.util.Util;
import com.tibo.webtv.web.TiboLog;
import com.tibo.webtv.web.WebHelper3;
import android.content.Context;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.media.MediaPlayer.OnErrorListener;
import android.media.MediaPlayer.OnInfoListener;
import android.media.MediaPlayer.OnPreparedListener;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Handler;
import android.util.AttributeSet;
import android.widget.Toast;
import android.widget.VideoView;
public class CustomVideoView extends VideoView implements OnPreparedListener,OnErrorListener,OnInfoListener,OnCompletionListener
{
private long buffer_start_time;
private long buffer_end_time;
private String token;
private Handler handler = new Handler();
public CustomVideoView(Context context)
{
super(context);
}
public CustomVideoView(Context context, AttributeSet attrs)
{
super(context, attrs);
setOnPreparedListener(this);
setOnErrorListener(this);
setOnInfoListener(this);
}
public CustomVideoView(Context context, AttributeSet attrs, int defStyle)
{
super(context, attrs, defStyle);
}
public TVChannelObject getCurrentPlayingChannel()
{
return current_playing_channel;
}
public void setCurrentPlayingChannel(TVChannelObject current_playing_channel)
{
this.current_playing_channel = current_playing_channel;
}
public TVChannelObject getPreviousPlayingChannel()
{
return previous_playing_channel;
}
public void setPreviousPlayingChannel(TVChannelObject previous_playing_channel)
{
this.previous_playing_channel = previous_playing_channel;
}
private TVChannelObject current_playing_channel;
private TVChannelObject previous_playing_channel;
private String access_way;
private Date stream_started_time;
private long stream_play_time;
private boolean FLAG_STREAM_STARTED;
private String error_code;
@Override
public void stopPlayback()
{
new WatchingTime().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
super.stopPlayback();
}
@Override
public void onPrepared(MediaPlayer mp)
{
log.i("on Prepared");
FLAG_STREAM_STARTED = true;
stream_started_time = Calendar.getInstance().getTime();
mp.start();
}
@Override
public boolean onError(MediaPlayer mp, int what, int extra)
{
log.i("on onError");
error_code = what + "";
Toast.makeText(getContext(),getContext().getString(R.string.videoerror) + " " + error_code, Toast.LENGTH_LONG).show();
new BlackScreenError().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
if(what == MediaPlayer.MEDIA_ERROR_SERVER_DIED)
mp.reset();
else if(what == MediaPlayer.MEDIA_ERROR_UNKNOWN)
mp.reset();
return true;
};
@Override
public boolean onInfo(MediaPlayer mp, int what, int extra)
{
log.i("on onInfo");
if (what == MediaPlayer.MEDIA_INFO_BUFFERING_START)
{
buffer_start_time = System.currentTimeMillis();
}
else if (what == MediaPlayer.MEDIA_INFO_BUFFERING_END)
{
buffer_end_time = System.currentTimeMillis();
new Buffering_Problem().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
FLAG_STREAM_STARTED = false;
}
return true;
}
@Override
public void onCompletion(MediaPlayer mp)
{
super.setOnCompletionListener(this);
new WatchingTime().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
public void start(TVChannelObject channel)
{
super.start();
if(current_playing_channel == null)
{
current_playing_channel = channel;
}
else
{
previous_playing_channel = current_playing_channel;
current_playing_channel = channel;
Global.shared_preference.setValue(TiboCacheKey.PLAYING_CHANNEL, current_playing_channel.number);
Global.shared_preference.setValue(TiboCacheKey.LAST_CHANNEL_VIEWED, previous_playing_channel.number);
}
this.access_way = "-1";
}
public synchronized void start(TVChannelObject channel,String access_way)
{
super.start();
if(isPlaying())
{
this.stopPlayback();
}
if(current_playing_channel == null)
{
current_playing_channel = channel;
}
else
{
previous_playing_channel = current_playing_channel;
current_playing_channel = channel;
Global.shared_preference.setValue(TiboCacheKey.PLAYING_CHANNEL, current_playing_channel.number);
if(!utility.stringCompareIgnoreCase(current_playing_channel.videotype, "2"))
{
Global.shared_preference.setValue(TiboCacheKey.LAST_CHANNEL_VIEWED, current_playing_channel.number);
}
}
this.access_way = access_way;
if (current_playing_channel.token.trim().toLowerCase(Locale.getDefault()).toCharArray()[0] == '1')
{
log.i("Channel with token!!!");
new PlayStreamWithToken().execute("");
}
else
{
log.i("Channel without token!!!");
token = "";
setVideoURI(Uri.parse(current_playing_channel.url));
start();
closePlayerActivityAfterSpecificTime(1000 * 60 * 120);
}
new ChannelHits().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
private void closePlayerActivityAfterSpecificTime(int milliseconds)
{
handler.removeCallbacks(ClosePlayerActivity);
handler.postDelayed(ClosePlayerActivity, milliseconds);
}
private Runnable ClosePlayerActivity = new Runnable() {
public void run() {
new ClosePlayerActivityAfterInActivity().execute(0);
}
};
private class PlayStreamWithToken extends AsyncTask<String, String, String>
{
ServerResponseObject<String> token_response = null;
@Override
protected void onPreExecute()
{
super.onPreExecute();
}
@Override
protected String doInBackground(String... params)
{
Thread.currentThread().setName("get token");
log.i("Channel with token!!!");
log.i("token url",current_playing_channel.TokenUrl);
try
{
token_response = WebHelper3.getToken(current_playing_channel.TokenUrl);
if(token_response != null)
{
if(token_response.status_code < 300)
{
if(!utility.stringCompareIgnoreCase(token_response.extra_data, ""))
{
token = token_response.extra_data;
log.i("token",token);
return Util.RESPONSE_OK;
}
}
else
{
//TODO handle error
return Util.RESPONSE_ERROR;
}
}
else
{
//TODO hanlde
token = "";
return Util.RESPONSE_NULL;
}
}
catch (ConnectTimeoutException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
return Util.RESPONSE_TIME_OUT;
}
return "";
}
protected void onPostExecute(String response)
{
if(utility.stringCompareIgnoreCase(response, Util.RESPONSE_OK))
{
String channel_url_to_play = current_playing_channel.url;
channel_url_to_play += token.trim();
log.i("url to play with token :", channel_url_to_play);
setVideoURI(Uri.parse(channel_url_to_play));
start();
closePlayerActivityAfterSpecificTime(1000 * 60 * 120);
}
else if(utility.stringCompareIgnoreCase(response, Util.RESPONSE_TIME_OUT))
{
//TODO handle timout and null
}
}
}
private class ClosePlayerActivityAfterInActivity extends AsyncTask<Integer, Integer, Integer>
{
@Override
protected Integer doInBackground(Integer... params)
{
Thread.currentThread().setName("SleepTask");
return 0;
}
@Override
protected void onPostExecute(Integer result)
{
if (isPlaying())
{
stopPlayback();
}
PlayerActivity.this_activity.finish();
}
}
private class Buffering_Problem extends AsyncTask<Integer, Integer, Integer>
{
@Override
protected void onPreExecute()
{
super.onPreExecute();
}
@Override
protected Integer doInBackground(Integer... params)
{
Thread.currentThread().setName("Buffering problem Custom VideoView");
if (FLAG_STREAM_STARTED)
{
TiboLog.logBufferingError(TiboLog.LIVE_TV_BUFFER_ERRORS,current_playing_channel.number, buffer_end_time - buffer_start_time, "Warning");
}
else
{
TiboLog.logBufferingError(TiboLog.LIVE_TV_BUFFER_ERRORS,current_playing_channel.number, buffer_end_time - buffer_start_time, "Error");
}
buffer_end_time = 0;
buffer_start_time = 0;
return 0;
}
}
private class BlackScreenError extends AsyncTask<Integer, Integer, Integer>
{
@Override
protected void onPreExecute()
{
super.onPreExecute();
}
@Override
protected Integer doInBackground(Integer... params)
{
Thread.currentThread().setName("Black Screen Error");
try
{
TiboLog.logSendError(TiboLog.LOGTYPE_ERROR,current_playing_channel.number, "Error Black Screen " + error_code);
}
catch (Exception e)
{
e.printStackTrace();
}
return 0;
}
}
private class ChannelHits extends AsyncTask<Integer, Integer, Integer>
{
@Override
protected void onPreExecute()
{
super.onPreExecute();
}
@Override
protected Integer doInBackground(Integer... params)
{
Thread.currentThread().setName("Channel Hit log");
TiboLog.logChannelHit(TiboLog.LIVE_TV_HITS,current_playing_channel.number, access_way, previous_playing_channel.number);
return 0;
}
}
private class WatchingTime extends AsyncTask<Integer, Integer, Integer>
{
@Override
protected void onPreExecute()
{
super.onPreExecute();
}
@Override
protected Integer doInBackground(Integer... params)
{
Thread.currentThread().setName("Watching Time Log");
if(stream_started_time != null)
{
long stream_ended_time = Calendar.getInstance().getTime().getTime();
stream_play_time = stream_ended_time - stream_started_time.getTime();
int playtime_in_seconds = (int) (stream_play_time)/1000;
log.i("playtime_in_seconds",playtime_in_seconds+"");
if (playtime_in_seconds >= 15 && playtime_in_seconds < 108000)
{
TiboLog.sendWatchingTime(TiboLog.LIVE_TV_WATCHING_TIME, current_playing_channel.number, playtime_in_seconds + "");
}
}
return 0;
}
}
}
xml文件如下:
<RelativeLayout
android:id="@+id/media_player_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<com.tibo.webtv.CustomVideoView --line 13
android:id="@+id/surface_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_gravity="center" />
</RelativeLayout>
当我在 android 4.1 上运行这个 apk 时, Activity 崩溃并且日志消息是:
11-13 11:36:27.962: E/AndroidRuntime(1040): FATAL EXCEPTION: main
11-13 11:36:27.962: E/AndroidRuntime(1040): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.tibo.webtv/com.tibo.webtv.activities.PlayerActivity}: android.view.InflateException: Binary XML file line #13: Error inflating class com.webtv.CustomVideoView
11-13 11:36:27.962: E/AndroidRuntime(1040): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
11-13 11:36:27.962: E/AndroidRuntime(1040): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
11-13 11:36:27.962: E/AndroidRuntime(1040): at android.app.ActivityThread.access$600(ActivityThread.java:130)
11-13 11:36:27.962: E/AndroidRuntime(1040): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
11-13 11:36:27.962: E/AndroidRuntime(1040): at android.os.Handler.dispatchMessage(Handler.java:99)
11-13 11:36:27.962: E/AndroidRuntime(1040): at android.os.Looper.loop(Looper.java:137)
11-13 11:36:27.962: E/AndroidRuntime(1040): at android.app.ActivityThread.main(ActivityThread.java:4745)
11-13 11:36:27.962: E/AndroidRuntime(1040): at java.lang.reflect.Method.invokeNative(Native Method)
11-13 11:36:27.962: E/AndroidRuntime(1040): at java.lang.reflect.Method.invoke(Method.java:511)
11-13 11:36:27.962: E/AndroidRuntime(1040): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
11-13 11:36:27.962: E/AndroidRuntime(1040): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
11-13 11:36:27.962: E/AndroidRuntime(1040): at dalvik.system.NativeStart.main(Native Method)
11-13 11:36:27.962: E/AndroidRuntime(1040): Caused by: android.view.InflateException: Binary XML file line #13: Error inflating class com.webtv.CustomVideoView
11-13 11:36:27.962: E/AndroidRuntime(1040): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:698)
11-13 11:36:27.962: E/AndroidRuntime(1040): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
11-13 11:36:27.962: E/AndroidRuntime(1040): at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
11-13 11:36:27.962: E/AndroidRuntime(1040): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
11-13 11:36:27.962: E/AndroidRuntime(1040): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
11-13 11:36:27.962: E/AndroidRuntime(1040): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
11-13 11:36:27.962: E/AndroidRuntime(1040): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:256)
11-13 11:36:27.962: E/AndroidRuntime(1040): at android.app.Activity.setContentView(Activity.java:1867)
11-13 11:36:27.962: E/AndroidRuntime(1040): at com.tibo.webtv.activities.PlayerActivity.onCreate(PlayerActivity.java:188)
11-13 11:36:27.962: E/AndroidRuntime(1040): at android.app.Activity.performCreate(Activity.java:5008)
11-13 11:36:27.962: E/AndroidRuntime(1040): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
11-13 11:36:27.962: E/AndroidRuntime(1040): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
11-13 11:36:27.962: E/AndroidRuntime(1040): ... 11 more
11-13 11:36:27.962: E/AndroidRuntime(1040): Caused by: java.lang.ClassNotFoundException: com.webtv.CustomVideoView
11-13 11:36:27.962: E/AndroidRuntime(1040): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
11-13 11:36:27.962: E/AndroidRuntime(1040): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
11-13 11:36:27.962: E/AndroidRuntime(1040): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
11-13 11:36:27.962: E/AndroidRuntime(1040): at android.view.LayoutInflater.createView(LayoutInflater.java:552)
11-13 11:36:27.962: E/AndroidRuntime(1040): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
11-13 11:36:27.962: E/AndroidRuntime(1040): ... 22 more
我想问题出在 OnInfoListener 上,因为当我删除它时一切正常。
最佳答案
问题出在包名上。交叉检查您在 xml 中使用的完全限定类名和您的类定义。简而言之,当您按下 ctrl+鼠标左键时,您应该被重定向到类定义。
它应该是 com.packagename.yourCustomclassName
关于android - 二进制 XML 文件行 #13 : Error inflating class on a class that extends VideoView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33691301/
今天我在一个 Java 应用程序中看到了几种不同的加载文件的方法。 文件:/ 文件:// 文件:/// 这三个 URL 开头有什么区别?使用它们的首选方式是什么? 非常感谢 斯特凡 最佳答案 file
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引起辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the he
我有一个 javascript 文件,并且在该方法中有一个“测试”方法,我喜欢调用 C# 函数。 c# 函数与 javascript 文件不在同一文件中。 它位于 .cs 文件中。那么我该如何管理 j
需要检查我使用的文件/目录的权限 //filePath = path of file/directory access denied by user ( in windows ) File fil
我在一个目录中有很多 java 文件,我想在我的 Intellij 项目中使用它。但是我不想每次开始一个新项目时都将 java 文件复制到我的项目中。 我知道我可以在 Visual Studio 和
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 这个问题似乎不是关于 a specific programming problem, a software
我有 3 个组件的 Twig 文件: 文件 1: {# content-here #} 文件 2: {{ title-here }} {# content-here #}
我得到了 mod_ldap.c 和 mod_authnz_ldap.c 文件。我需要使用 Linux 命令的 mod_ldap.so 和 mod_authnz_ldap.so 文件。 最佳答案 从 c
我想使用PIE在我的项目中使用 IE7。 但是我不明白的是,我只能在网络服务器上使用 .htc 文件吗? 我可以在没有网络服务器的情况下通过浏览器加载的本地页面中使用它吗? 我在 PIE 的文档中看到
我在 CI 管道中考虑这一点,我应该首先构建和测试我的应用程序,结果应该是一个 docker 镜像。 我想知道使用构建环境在构建服务器上构建然后运行测试是否更常见。也许为此使用构建脚本。最后只需将 j
using namespace std; struct WebSites { string siteName; int rank; string getSiteName() {
我是 Linux 新手,目前正在尝试使用 ginkgo USB-CAN 接口(interface) 的 API 编程功能。为了使用 C++ 对 API 进行编程,他们提供了库文件,其中包含三个带有 .
我刚学C语言,在实现一个程序时遇到了问题将 test.txt 文件作为程序的输入。 test.txt 文件的内容是: 1 30 30 40 50 60 2 40 30 50 60 60 3 30 20
如何连接两个tcpdump文件,使一个流量在文件中出现一个接一个?具体来说,我想“乘以”一个 tcpdump 文件,这样所有的 session 将一个接一个地按顺序重复几次。 最佳答案 mergeca
我有一个名为 input.MP4 的文件,它已损坏。它来自闭路电视摄像机。我什么都试过了,ffmpeg , VLC 转换,没有运气。但是,我使用了 mediainfo和 exiftool并提取以下信息
我想做什么? 我想提取 ISO 文件并编辑其中的文件,然后将其重新打包回 ISO 文件。 (正如你已经读过的) 我为什么要这样做? 我想开始修改 PSP ISO,为此我必须使用游戏资源、 Assets
给定一个 gzip 文件 Z,如果我将其解压缩为 Z',有什么办法可以重新压缩它以恢复完全相同的 gzip 文件 Z?在粗略阅读了 DEFLATE 格式后,我猜不会,因为任何给定的文件都可能在 DEF
我必须从数据库向我的邮件 ID 发送一封带有附件的邮件。 EXEC msdb.dbo.sp_send_dbmail @profile_name = 'Adventure Works Admin
我有一个大的 M4B 文件和一个 CUE 文件。我想将其拆分为多个 M4B 文件,或将其拆分为多个 MP3 文件(以前首选)。 我想在命令行中执行此操作(OS X,但如果需要可以使用 Linux),而
快速提问。我有一个没有实现文件的类的项目。 然后在 AppDelegate 我有: #import "AppDelegate.h" #import "SomeClass.h" @interface A
我是一名优秀的程序员,十分优秀!