rexseeDownload.download('http://www.rexsee.com/images/test.wmv'); function onDownloadFinished(url,path){ rexseeVideoPlayer.start(path,'window-dim-amount:0;window-moveable:true;window-modeless:true;window-cancelable:false;width:300;height:200;border-width:0px;',true); } rexseeVideoPlayer.start('http://www.rexsee.com/images/test.wmv','window-dim-amount:0;window-moveable:true;window-modeless:true;window-cancelable:false;width:300;height:200;border-width:0px;',false); rexseeVideoPlayer.pause(); rexseeVideoPlayer.resume(); rexseeVideoPlayer.stop();
rexseeVideoPlayer.seekTo(2000);
alert(rexseeVideoPlayer.getDuration());
alert(rexseeVideoPlayer.isPlaying());
/* * Copyright (C) 2011 The Rexsee Open Source Project * * Licensed under the Rexsee License, Version 1.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.rexsee.com/CN/legal/license.html * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package rexsee.multimedia; import rexsee.core.browser.JavascriptInterface; import rexsee.core.browser.RexseeBrowser; import android.content.Context; import android.media.AudioManager; public class RexseeVideoPlayer implements JavascriptInterface { private static final String INTERFACE_NAME = "VideoPlayer"; @Override public String getInterfaceName() { return mBrowser.application.resources.prefix + INTERFACE_NAME; } @Override public JavascriptInterface getInheritInterface(RexseeBrowser childBrowser) { return this; } @Override public JavascriptInterface getNewInterface(RexseeBrowser childBrowser) { return new RexseeVideoPlayer(childBrowser); } private final RexseeBrowser mBrowser; private final Context mContext; private VideoDialog mVideoDialog = null; public RexseeVideoPlayer(RexseeBrowser browser) { mBrowser = browser; mContext = browser.getContext(); } private boolean checkStatus() { if (mVideoDialog == null || mVideoDialog.videoView.mediaPlayer == null) { mBrowser.exception(getInterfaceName(), "The video player is not started, please call start()."); return false; } else { return true; } } //JavaScript Interface public boolean start(String url, String style, boolean looping) { stop(); url = mBrowser.urlListeners.getAbsoluteUrl(url); mVideoDialog = new VideoDialog(mBrowser, url, style, looping); mVideoDialog.start(); return true; } public boolean stop() { if (mVideoDialog == null) return true; try { if (mVideoDialog.videoView.mediaPlayer != null) { mVideoDialog.videoView.mediaPlayer.stop(); mVideoDialog.videoView.mediaPlayer.release(); mVideoDialog.videoView.mediaPlayer = null; } mVideoDialog.dismiss(); mVideoDialog = null; return true; } catch (Exception e) { mBrowser.exception(getInterfaceName(), e); return false; } } public boolean pause() { if (!checkStatus()) return false; if (!mVideoDialog.videoView.mediaPlayer.isPlaying()) return true; try { mVideoDialog.videoView.mediaPlayer.pause(); return true; } catch (Exception e) { mBrowser.exception(getInterfaceName(), e); return false; } } public boolean resume() { if (!checkStatus()) return false; try { mVideoDialog.videoView.mediaPlayer.start(); return true; } catch (Exception e) { mBrowser.exception(getInterfaceName(), e); return false; } } public boolean seekTo(int milliseconds) { if (!checkStatus()) return false; try { mVideoDialog.videoView.mediaPlayer.seekTo(milliseconds); return true; } catch (Exception e) { mBrowser.exception(getInterfaceName(), e); return false; } } public int getDuration() { if (!checkStatus()) return -1; try { return mVideoDialog.videoView.mediaPlayer.getDuration(); } catch (Exception e) { mBrowser.exception(getInterfaceName(), e); return -1; } } public int getCurrentPosition() { if (!checkStatus()) return -1; try { return mVideoDialog.videoView.mediaPlayer.getCurrentPosition(); } catch (Exception e) { mBrowser.exception(getInterfaceName(), e); return -1; } } public int getVideoWidth() { if (!checkStatus()) return -1; try { return mVideoDialog.videoView.mediaPlayer.getVideoWidth(); } catch (Exception e) { mBrowser.exception(getInterfaceName(), e); return -1; } } public int getVideoHeight() { if (!checkStatus()) return -1; try { return mVideoDialog.videoView.mediaPlayer.getVideoHeight(); } catch (Exception e) { mBrowser.exception(getInterfaceName(), e); return -1; } } public boolean isPlaying() { if (!checkStatus()) return false; return mVideoDialog.videoView.mediaPlayer.isPlaying(); } public boolean isLooping() { if (!checkStatus()) return false; return mVideoDialog.videoView.mediaPlayer.isLooping(); } public boolean setVolume(float volume) { if (!checkStatus()) return false; if (volume < 0 || volume > 1) { mBrowser.exception(getInterfaceName(), "The volumn must between 0 and 1."); return false; } AudioManager mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE); mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, Math.round((mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC) * volume)), 0); return true; } }