|  | 
|  | 1 | +// Copyright (c) 2016 Intel Corporation. All rights reserved. | 
|  | 2 | +// Use of this source code is governed by a BSD-style license that can be | 
|  | 3 | +// found in the LICENSE file. | 
|  | 4 | + | 
|  | 5 | +package org.xwalk.core.internal; | 
|  | 6 | + | 
|  | 7 | +import android.content.Context; | 
|  | 8 | +import android.media.MediaPlayer.OnBufferingUpdateListener; | 
|  | 9 | +import android.media.MediaPlayer.OnCompletionListener; | 
|  | 10 | +import android.media.MediaPlayer.OnErrorListener; | 
|  | 11 | +import android.media.MediaPlayer.OnPreparedListener; | 
|  | 12 | +import android.media.MediaPlayer.OnSeekCompleteListener; | 
|  | 13 | +import android.media.MediaPlayer.OnVideoSizeChangedListener; | 
|  | 14 | +import android.media.MediaPlayer.TrackInfo; | 
|  | 15 | +import android.net.Uri; | 
|  | 16 | +import android.util.Log; | 
|  | 17 | +import android.view.Surface; | 
|  | 18 | + | 
|  | 19 | +import java.io.FileDescriptor; | 
|  | 20 | +import java.util.HashMap; | 
|  | 21 | +import java.util.Map; | 
|  | 22 | + | 
|  | 23 | +import org.chromium.media.ExternalMediaPlayer; | 
|  | 24 | + | 
|  | 25 | +@XWalkAPI(createExternally = true) | 
|  | 26 | +public class XWalkMediaPlayerInternal extends ExternalMediaPlayer { | 
|  | 27 | +    private final static String TAG = "XWalkMediaPlayerInternal"; | 
|  | 28 | + | 
|  | 29 | +    private void unsupported() { | 
|  | 30 | +        Log.e(TAG, "ERROR: The function must be implemented"); | 
|  | 31 | +        throw new UnsupportedOperationException(); | 
|  | 32 | +    } | 
|  | 33 | + | 
|  | 34 | +    /** | 
|  | 35 | +     * Sets the Surface to be used as the sink for the video portion of the media. | 
|  | 36 | +     * @param surface the Surface to be used for the video portion of the media. | 
|  | 37 | +     * @since 7.0 | 
|  | 38 | +     */ | 
|  | 39 | +    @XWalkAPI | 
|  | 40 | +    public void setSurface(Surface surface) { | 
|  | 41 | +        unsupported(); | 
|  | 42 | +    } | 
|  | 43 | + | 
|  | 44 | +    /** | 
|  | 45 | +     * Sets the data source as a content Uri. | 
|  | 46 | +     * @param context the Context to use when resolving the Uri. | 
|  | 47 | +     * @param uri the Content URI of the data you want to play. | 
|  | 48 | +     * @param headers the headers to be sent together with the request for the data. | 
|  | 49 | +     * @since 7.0 | 
|  | 50 | +     */ | 
|  | 51 | +    @XWalkAPI | 
|  | 52 | +    public void setDataSource(Context context, Uri uri, Map<String, String> headers) { | 
|  | 53 | +        unsupported(); | 
|  | 54 | +    } | 
|  | 55 | + | 
|  | 56 | +    /** | 
|  | 57 | +     * Sets the data source (FileDescriptor) to use. | 
|  | 58 | +     * @param offset the offset into the file where the data to be played starts, in bytes. | 
|  | 59 | +     * @param length the length in bytes of the data to be played. | 
|  | 60 | +     * @since 7.0 | 
|  | 61 | +     */ | 
|  | 62 | +    @XWalkAPI | 
|  | 63 | +    public void setDataSource(FileDescriptor fd, long offset, long length) { | 
|  | 64 | +        unsupported(); | 
|  | 65 | +    } | 
|  | 66 | + | 
|  | 67 | +    /** | 
|  | 68 | +     * Sets the data source as a content Uri. | 
|  | 69 | +     * @param context the Context to use when resolving the Uri. | 
|  | 70 | +     * @param uri the Content URI of the data you want to play. | 
|  | 71 | +     * @since 7.0 | 
|  | 72 | +     */ | 
|  | 73 | +    @XWalkAPI | 
|  | 74 | +    public void setDataSource(Context context, Uri uri) { | 
|  | 75 | +        unsupported(); | 
|  | 76 | +    } | 
|  | 77 | + | 
|  | 78 | +    /** | 
|  | 79 | +     * Prepares the player for playback, asynchronously. | 
|  | 80 | +     * @since 7.0 | 
|  | 81 | +     */ | 
|  | 82 | +    @XWalkAPI | 
|  | 83 | +    public void prepareAsync() { | 
|  | 84 | +        unsupported(); | 
|  | 85 | +    } | 
|  | 86 | + | 
|  | 87 | +    /** | 
|  | 88 | +     * Checks whether the MediaPlayer is playing. | 
|  | 89 | +     * @since 7.0 | 
|  | 90 | +     */ | 
|  | 91 | +    @XWalkAPI | 
|  | 92 | +    public boolean isPlaying() { | 
|  | 93 | +        unsupported(); | 
|  | 94 | +        return false; | 
|  | 95 | +    } | 
|  | 96 | + | 
|  | 97 | +    /** | 
|  | 98 | +     * Returns the width of the video. | 
|  | 99 | +     * @since 7.0 | 
|  | 100 | +     */ | 
|  | 101 | +    @XWalkAPI | 
|  | 102 | +    public int getVideoWidth() { | 
|  | 103 | +        unsupported(); | 
|  | 104 | +        return 0; | 
|  | 105 | +    } | 
|  | 106 | + | 
|  | 107 | +    /** | 
|  | 108 | +     * Returns the height of the video. | 
|  | 109 | +     * @since 7.0 | 
|  | 110 | +     */ | 
|  | 111 | +    @XWalkAPI | 
|  | 112 | +    public int getVideoHeight() { | 
|  | 113 | +        unsupported(); | 
|  | 114 | +        return 0; | 
|  | 115 | +    } | 
|  | 116 | + | 
|  | 117 | +    /** | 
|  | 118 | +     * Gets the current playback position. | 
|  | 119 | +     * @since 7.0 | 
|  | 120 | +     */ | 
|  | 121 | +    @XWalkAPI | 
|  | 122 | +    public int getCurrentPosition() { | 
|  | 123 | +        unsupported(); | 
|  | 124 | +        return 0; | 
|  | 125 | +    } | 
|  | 126 | + | 
|  | 127 | +    /** | 
|  | 128 | +     * Gets the duration of the file. | 
|  | 129 | +     * @since 7.0 | 
|  | 130 | +     */ | 
|  | 131 | +    @XWalkAPI | 
|  | 132 | +    public int getDuration() { | 
|  | 133 | +        unsupported(); | 
|  | 134 | +        return 0; | 
|  | 135 | +    } | 
|  | 136 | + | 
|  | 137 | +    /** | 
|  | 138 | +     * Releases resources associated with this MediaPlayer object. | 
|  | 139 | +     * @since 7.0 | 
|  | 140 | +     */ | 
|  | 141 | +    @XWalkAPI | 
|  | 142 | +    public void release() { | 
|  | 143 | +        unsupported(); | 
|  | 144 | +    } | 
|  | 145 | + | 
|  | 146 | +    /** | 
|  | 147 | +     * Sets the volume on this player. | 
|  | 148 | +     * @since 7.0 | 
|  | 149 | +     */ | 
|  | 150 | +    @XWalkAPI | 
|  | 151 | +    public void setVolume(float volume1, float volume2) { | 
|  | 152 | +        unsupported(); | 
|  | 153 | +    } | 
|  | 154 | + | 
|  | 155 | +    /** | 
|  | 156 | +     * Starts or resumes playback. If playback had previously been paused, | 
|  | 157 | +     * playback will continue from where it was paused. If playback had been stopped, | 
|  | 158 | +     * or never started before, playback will start at the beginning. | 
|  | 159 | +     * @since 7.0 | 
|  | 160 | +     */ | 
|  | 161 | +    @XWalkAPI | 
|  | 162 | +    public void start() { | 
|  | 163 | +        unsupported(); | 
|  | 164 | +    } | 
|  | 165 | + | 
|  | 166 | +    /** | 
|  | 167 | +     * Pauses playback. Call start() to resume. | 
|  | 168 | +     * @since 7.0 | 
|  | 169 | +     */ | 
|  | 170 | +    @XWalkAPI | 
|  | 171 | +    public void pause() { | 
|  | 172 | +        unsupported(); | 
|  | 173 | +    } | 
|  | 174 | + | 
|  | 175 | +    /** | 
|  | 176 | +     * Seeks to specified time position. | 
|  | 177 | +     * @since 7.0 | 
|  | 178 | +     */ | 
|  | 179 | +    @XWalkAPI | 
|  | 180 | +    public void seekTo(int msec) { | 
|  | 181 | +        unsupported(); | 
|  | 182 | +    } | 
|  | 183 | + | 
|  | 184 | +    /** | 
|  | 185 | +     * Returns an array of track information. | 
|  | 186 | +     * @since 7.0 | 
|  | 187 | +     */ | 
|  | 188 | +    @XWalkAPI | 
|  | 189 | +    public TrackInfo[] getTrackInfo() { | 
|  | 190 | +        unsupported(); | 
|  | 191 | +        return null; | 
|  | 192 | +    } | 
|  | 193 | + | 
|  | 194 | +    /** | 
|  | 195 | +     * Register a callback to be invoked when the status of a network stream's buffer has changed. | 
|  | 196 | +     * @param listener the callback that will be run. | 
|  | 197 | +     * @since 7.0 | 
|  | 198 | +     */ | 
|  | 199 | +    @XWalkAPI | 
|  | 200 | +    public void setOnBufferingUpdateListener(OnBufferingUpdateListener listener) { | 
|  | 201 | +        unsupported(); | 
|  | 202 | +    } | 
|  | 203 | + | 
|  | 204 | +    /** | 
|  | 205 | +     * Register a callback to be invoked when the end of a media source has been reached during playback. | 
|  | 206 | +     * @param listener the callback that will be run. | 
|  | 207 | +     * @since 7.0 | 
|  | 208 | +     */ | 
|  | 209 | +    @XWalkAPI | 
|  | 210 | +    public void setOnCompletionListener(OnCompletionListener listener) { | 
|  | 211 | +        unsupported(); | 
|  | 212 | +    } | 
|  | 213 | + | 
|  | 214 | +    /** | 
|  | 215 | +     * Register a callback to be invoked when an error has happened during an asynchronous operation. | 
|  | 216 | +     * @param listener the callback that will be run. | 
|  | 217 | +     * @since 7.0 | 
|  | 218 | +     */ | 
|  | 219 | +    @XWalkAPI | 
|  | 220 | +    public void setOnErrorListener(OnErrorListener listener) { | 
|  | 221 | +        unsupported(); | 
|  | 222 | +    } | 
|  | 223 | + | 
|  | 224 | +    /** | 
|  | 225 | +     * Register a callback to be invoked when the media source is ready for playback. | 
|  | 226 | +     * @param listener the callback that will be run. | 
|  | 227 | +     * @since 7.0 | 
|  | 228 | +     */ | 
|  | 229 | +    @XWalkAPI | 
|  | 230 | +    public void setOnPreparedListener(OnPreparedListener listener) { | 
|  | 231 | +        unsupported(); | 
|  | 232 | +    } | 
|  | 233 | + | 
|  | 234 | +    /** | 
|  | 235 | +     * Register a callback to be invoked when a seek operation has been completed. | 
|  | 236 | +     * @param listener the callback that will be run. | 
|  | 237 | +     * @since 7.0 | 
|  | 238 | +     */ | 
|  | 239 | +    @XWalkAPI | 
|  | 240 | +    public void setOnSeekCompleteListener(OnSeekCompleteListener listener) { | 
|  | 241 | +        unsupported(); | 
|  | 242 | +    } | 
|  | 243 | + | 
|  | 244 | +    /** | 
|  | 245 | +     * Register a callback to be invoked when the video size is known or updated. | 
|  | 246 | +     * @param listener the callback that will be run. | 
|  | 247 | +     * @since 7.0 | 
|  | 248 | +     */ | 
|  | 249 | +    @XWalkAPI | 
|  | 250 | +    public void setOnVideoSizeChangedListener(OnVideoSizeChangedListener listener) { | 
|  | 251 | +        unsupported(); | 
|  | 252 | +    } | 
|  | 253 | +} | 
0 commit comments