- 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/
猫f1.txt阿曼维沙尔阿杰贾伊维杰拉胡尔曼尼什肖比特批评塔夫林现在输出应该符合上面给定的条件 最佳答案 您可以在文件读取循环中设置一个计数器并打印它, 计数=0 读取行时做 让我们数一数++ if
我正在尝试查找文件 1 和文件 2 中的共同行。如果公共(public)行存在,我想写入文件 2 中的行,否则打印文件 1 中的非公共(public)行。fin1 和 fin2 是这里的文件句柄。它读
我有这个 SQL 脚本: CREATE TABLE `table_1` ( `IDTable_1` int(11) NOT NULL, PRIMARY KEY (`IDTable_1`) );
我有 512 行要插入到数据库中。我想知道提交多个插入内容是否比提交一个大插入内容有任何优势。例如 1x 512 行插入 -- INSERT INTO mydb.mytable (id, phonen
如何从用户中选择user_id,SUB(row, row - 1),其中user_id=@userid我的表用户,id 为 1、3、4、10、11、23...(不是++) --id---------u
我曾尝试四处寻找解决此问题的最佳方法,但我找不到此类问题的任何先前示例。 我正在构建一个基于超本地化的互联网购物中心,该区域分为大约 3000 个区域。每个区域包含大约 300 个项目。它们是相似的项
preg_match('|phpVersion = (.*)\n|',$wampConfFileContents,$result); $phpVersion = str_replace('"','',
我正在尝试创建一个正则表达式,使用“搜索并替换全部”删除 200 个 txt 文件的第一行和最后 10 行 我尝试 (\s*^(\h*\S.*)){10} 删除包含的前 10 行空白,但效果不佳。 最
下面的代码从数据库中获取我需要的信息,但没有打印出所有信息。首先,我知道它从表中获取了所有正确的信息,因为我已经在 sql Developer 中尝试过查询。 public static void m
很难说出这里问的是什么。这个问题是含糊的、模糊的、不完整的、过于宽泛的或修辞性的,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开它,visit the help center 。 已关
我试图在两个表中插入记录,但出现异常。您能帮我解决这个问题吗? 首先我尝试了下面的代码。 await _testRepository.InsertAsync(test); await _xyzRepo
这个基本的 bootstrap CSS 显示 1 行 4 列: Text Text Text
如果我想从表中检索前 10 行,我将使用以下代码: SELECT * FROM Persons LIMIT 10 我想知道的是如何检索前 10 个结果之后的 10 个结果。 如果我在下面执行这段代码,
今天我开始使用 JexcelApi 并遇到了这个:当您尝试从特定位置获取元素时,不是像您通常期望的那样使用sheet.getCell(row,col),而是使用sheet.getCell(col,ro
我正在尝试在我的网站上开发一个用户个人资料系统,其中包含用户之前发布的 3 个帖子。我可以让它选择前 3 条记录,但它只会显示其中一条。我是不是因为凌晨 2 点就想编码而变得愚蠢? query($q)
我在互联网上寻找答案,但找不到任何答案。 (我可能问错了?)我有一个看起来像这样的表: 我一直在使用查询: SELECT title, date, SUM(money) FROM payments W
我有以下查询,我想从数据库中获取 100 个项目,但 host_id 多次出现在 urls 表中,我想每个 host_id 从该表中最多获取 10 个唯一行。 select * from urls j
我的数据库表中有超过 500 行具有特定日期。 查询特定日期的行。 select * from msgtable where cdate='18/07/2012' 这将返回 500 行。 如何逐行查询
我想使用 sed 从某一行开始打印 n 行、跳过 n 行、打印 n 行等,直到文本文件结束。例如在第 4 行声明,打印 5-9,跳过 10-14,打印 15-19 等 来自文件 1 2 3 4 5 6
我目前正在执行验证过程来检查用户的旧密码,但问题是我无法理解为什么我的查询返回零行,而预期它有 1 行。另一件事是,即使我不将密码文本转换为 md5,哈希密码仍然得到正确的答案,但我不知道为什么会发生
我是一名优秀的程序员,十分优秀!