我想编写一个小的离子/角度应用程序,我从远程服务器加载一个动态mp3文件并按下按钮播放它或者如果选中它我会自动播放它.我尝试使用简单<audio></audio>但我不确定这是否是这个的好方法...
码:
HTML
<audio id="player">
<source id="source" src="http://remote.address.com/example.mp3"></source>
</audio>
Run Code Online (Sandbox Code Playgroud)
JavaScript的
play(){
var audio= document.getElementById('player');
audio.play();
}
Run Code Online (Sandbox Code Playgroud) 我希望在运行后或视图消失时移除观察者.这是代码,但有时观察者已被删除,当我想再次删除它时.如何检查它是否仍然注册?
override func observeValueForKeyPath(keyPath: String, ofObject object: AnyObject, change: [NSObject : AnyObject], context: UnsafeMutablePointer<Void>) {
if(!didOnce){
if(keyPath == "myLocation"){
location = mapView.myLocation.coordinate;
self.mapView.animateToLocation(self.location!);
self.mapView.animateToZoom(15);
didOnce = true;
self.mapView.removeObserver(self, forKeyPath: "myLocation");
}
}
}
override func viewDidAppear(animated: Bool) {
didOnce = false;
}
override func viewWillDisappear(animated: Bool) {
if(!didOnce){
self.mapView.removeObserver(self, forKeyPath: "myLocation");
didOnce = true;
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个pdf查看器应用程序,我必须下载大的pdf文件(例如136mb)我正在使用retrofit2-beta2进行此过程.问题是我总是耗尽内存.我如何告诉改装我将下载一个大文件,请给我一个byteStream?
我的界面是:
@GET("url")
Call<ResponseBody> getData(params);
Run Code Online (Sandbox Code Playgroud)
我有一个ProgressResponseBody类,它正在扩展ResponseBody,我在这里设置progressListener,以便能够刷新我的进度条,
在onResponse函数中我只是得到了InputStream
InputStream input = response.body().byteStream();
FileOutputStream out = new FileOutputStream(file);
int bufferSize=1024;
byte[] buffer = new byte[bufferSize];
int len = 0;
while (len = input.read(buffer) != -1) {
out.write(buffer,0,len);
}
if(out!=null)
out.close();
Run Code Online (Sandbox Code Playgroud)
UPDATE
我已经加入了@Stream到接口,但现在我得到NetworkOnMainThreadException在ProgressResponseBody.java的误差在super.read(水槽,BYTECOUNT)抛出; 行.我怎么能把它放到一个单独的线程?
@Override
public BufferedSource source() throws IOException {
if (bufferedSource == null) {
bufferedSource = Okio.buffer(source(responseBody.source()));
}
return bufferedSource;
}
private Source source(Source source) {
return new ForwardingSource(source) {
long totalBytesRead = 0L;
@Override
public long read(Buffer sink, …Run Code Online (Sandbox Code Playgroud) 我正在开发一个Android定制的键盘,我想送胶粘物给我的朋友,例如Hangouts上从我的键盘.我为此添加了一些png.
当我使用android的共享api时,我必须首先选择要与之分享的应用程序.是否可以从键盘检测当前打开的应用程序?例如,如果我正在与环聊聊天,那么我想调用意图告诉它与"com.something.hangouts"分享
如果我在FB messenger然后告诉它"com.something.facebook.messenger"等...
我试着像这样:
fun getOpenedApplication() {
var am = this.getSystemService(ACTIVITY_SERVICE) as ActivityManager;
var l = am.getRecentTasks(1,
ActivityManager.RECENT_WITH_EXCLUDED);
var i = l.iterator();
var pm = this.packageManager;
while (i.hasNext()) {
try {
var intent = i.next().baseIntent;
var list = pm.queryIntentActivities(intent,
PackageManager.MATCH_DEFAULT_ONLY);
var c = pm.getApplicationLabel(pm.getApplicationInfo(
list[0].activityInfo.packageName,
PackageManager.GET_META_DATA));
Toast.makeText(this, "Application name: " + c.toString(),
Toast.LENGTH_LONG).show();
} catch (e: Exception) {
Toast.makeText(this,
"Application name not found: " + e.toString(),
Toast.LENGTH_LONG).show();
}
}
}
Run Code Online (Sandbox Code Playgroud)
但是效果不好......它会发回发射器或键盘.(随机)
我试图从最近的应用程序列表中获取第一个应用程序,但它无法正常工作
我有一个应用程序,其中一些屏幕应该是纵向模式,其中一些是横向模式.例如,主菜单是纵向,并且有一个相机按钮.相机应仅在横向上可用.我正在使用Storyboard和NavigationController.我应该在哪里以及如何做到这一点?
我已经尝试过包括
shouldAutorotate() -> Bool {return false or return true}
Run Code Online (Sandbox Code Playgroud)
既没有奏效.我已经设定了
supportedInterfaceOrientation
Run Code Online (Sandbox Code Playgroud)
对于我拥有的每个viewcontroller.什么都没有帮助.我需要一个功能,我可以调用强制屏幕进入横向/纵向模式.
我想DialogFragment用a 做空,LinearLayout然后在里面更改片段LinearLayout.例如,登录时第一个片段是3个按钮(Facebook,谷歌+,电子邮件登录),当有人按下电子邮件时,2.片段有一个布局,EditTexts如果谷歌或Facebook被按下,那么另一个片段出现一个ProgressBar.
这是我的空对话框布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:background="@drawable/dialog_background">
<LinearLayout
android:id="@+id/testFragmentController"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_margin="15dp"></LinearLayout>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
这是第一个片段的代码(我正在使用android注释):
@EFragment(R.layout.dialog)
public class FragmentGeneralDialog extends ClickDialogFragment {
@ViewById
LinearLayout testFragmentController;
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
Dialog dialog = super.onCreateDialog(savedInstanceState);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
this.setStyle(R.style.Dialog_No_Border, getTheme());
return dialog;
}
@AfterViews
void afterViews() {
loadActivity();
GlobalData.setFragmentContainer(testFragmentController);
activity.loadMenuFragment(FragmentSocialDialog_.class, new SlideLeftAnimation());
}
}
Run Code Online (Sandbox Code Playgroud)
loadMenuFragments(...) 这是:
public <T extends Fragment> T loadMenuFragment(final …Run Code Online (Sandbox Code Playgroud)