通过实现OnCompletionListener将数据源设置为不同的文件,我可以连续播放视频.没有问题.我调用reset()和prepare()就好了.
我无法弄清楚的是,如何消除数据源更改和新视频启动之间的1-2秒间隙屏幕闪烁.差距显示黑屏,我没有找到任何方法绕过它.
我已经尝试将父视图的背景设置为图像,但它设法绕过它.即使SurfaceView是透明的(默认情况下也是这样).我也尝试同时播放多个视频文件,并在一个结束而另一个应该启动时切换媒体播放器的显示.
我尝试的最后一件事是在后台显示第二个视图,我在视频"准备"时暂时显示,并在视频准备好开始时将其删除.这也不是很无缝.
有没有办法摆脱这种差距.在循环中运行视频非常有效,并且完全符合我的要求,除了它正在查看相同的视频而不是播放我选择的不同视频.
main.xml中
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:background="@drawable/background"
android:layout_height="fill_parent">
<SurfaceView
android:id="@+id/surface"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center">
</SurfaceView>
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)
Player.java
public class Player extends Activity implements
OnCompletionListener, MediaPlayer.OnPreparedListener, SurfaceHolder.Callback {
private MediaPlayer player;
private SurfaceView surface;
private SurfaceHolder holder;
public void onCreate(Bundle b) {
super.onCreate(b);
setContentView(R.layout.main);
surface = (SurfaceView)findViewById(R.id.surface);
holder = surface.getHolder();
holder.addCallback(this);
holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
}
public void onCompletion(MediaPlayer arg0) {
File clip = new File(Environment.getExternalStorageDirectory(),"file2.mp4");
playVideo(clip.getAbsolutePath());
}
public void onPrepared(MediaPlayer …
Run Code Online (Sandbox Code Playgroud) 我真的碰到了墙,需要一些帮助!谢谢你阅读这篇文章!
我正在编写一个应用程序,它与我的ROR Web服务器通信以获取数据库请求,并且非常感谢ActiveResource.但我现在还需要将文件上传到服务器,我打算使用看起来很棒的ASIHTTPRequest,我的问题是我只是不确定如何在ROR端交出POST请求...我正在使用回形针但真的碰到了一堵砖墙.
在ASIHTTP方面,我只是写作:
[request setData:data withFileName:@"photo.jpg" andContentType:@"image/jpeg" forKey:@"asset[image]"];
Run Code Online (Sandbox Code Playgroud)
在红宝石方面,我正在做......
class Asset < ActiveRecord::Base
validates_attachment_presence :image
has_attached_file :image
end
class AssetsController < ApplicationController
protect_from_forgery :only => [:update, :destroy]
.....
Run Code Online (Sandbox Code Playgroud)
但它总是失败,我很确定它与POST表单数据集有关,但我完全被卡住了.
我收到错误:
Run Code Online (Sandbox Code Playgroud)Parameters: {"assets"=>{"images"=>#<File:/var/folders/gM/gM15qjM2G3W0iVNaT1evD++++TI/-Tmp-/RackMultipart20091112-2285-2i0qq5-0>}} NoMethodError (You have a nil object when you didn't expect it! You might have expected an instance of ActiveRecord::Base. The error occurred while evaluating nil.[]): app/models/asset.rb:2 app/controllers/assets_controller.rb:46:in
'创建"
非常感谢任何帮助.
克里斯
谢谢!