removing WP8 Media APIS (Pictures, Playlist, Song Albums, etc...)
This commit is contained in:
Родитель
dec1c5a08f
Коммит
072b5cb828
|
@ -97,7 +97,6 @@ module TDev.Synth {
|
|||
})
|
||||
});
|
||||
return Utils.distinctStrings(kinds);
|
||||
/* ["Action","Appointment", "Appointment Collection", "Bluetooth Device", "Board", "Boolean", "Buffer", "Camera", "Cloud Picture", "Cloud Session", "Collection of Action", "Collection of Bluetooth Device", "Collection of DateTime", "Collection of Gamepad", "Collection of Number", "Collection of Picture", "Collection of Sound", "Collection of User", "Color", "Contact", "Contact Collection", "DateTime", "Device", "Device Collection", "Event Binding", "Form Builder", "Gamepad", "Json Builder", "Json Object", "Link", "Link Collection", "Location", "Location Collection", "Map", "Matrix","Message", "Message Collection", "Motion", "Nothing", "Number", "Number Collection", "Number Map", "OAuth Response", "Page", "Page Button", "Page Collection", "Picture", "Picture Album", "Picture Albums", "Pictures", "Place", "Place Collection", "Playlist", "Playlists", "Printer", "Printer Collection", "Song", "Song Album", "Song Albums", "Songs", "Sound", "Sprite", "Sprite Set", "String", "String Collection", "String Map", "TextBox", "Tile", "Timer", "Unfinished Type", "User", "Vector3", "Web Event Source", "Web Request", "Web Response", "Xml Object"] */
|
||||
}
|
||||
|
||||
export function listSingletonProperties(): IProperty[]{
|
||||
|
|
|
@ -26,41 +26,9 @@ module TDev.RT {
|
|||
//? Creates an invalid Picture instance
|
||||
export function picture() : Picture { return undefined; }
|
||||
|
||||
//? Creates an invalid Pictures instance
|
||||
//@ cap(media)
|
||||
export function pictures() : Pictures { return undefined; }
|
||||
|
||||
//? Creates an invalid Picture Album instance
|
||||
//@ cap(media)
|
||||
export function picture_album() : PictureAlbum { return undefined; }
|
||||
|
||||
//? Creates an invalid Picture Albums instance
|
||||
//@ cap(media)
|
||||
export function picture_albums() : PictureAlbums { return undefined; }
|
||||
|
||||
//? Creates an invalid Song instance
|
||||
export function song() : Song { return undefined; }
|
||||
|
||||
//? Creates an invalid Songs instance
|
||||
//@ cap(media)
|
||||
export function songs() : Songs { return undefined; }
|
||||
|
||||
//? Creates an invalid Song Album instance
|
||||
//@ cap(media)
|
||||
export function song_album() : SongAlbum { return undefined; }
|
||||
|
||||
//? Creates an invalid Song Albums instance
|
||||
//@ cap(media)
|
||||
export function song_albums() : SongAlbums { return undefined; }
|
||||
|
||||
//? Creates an invalid Playlist instance
|
||||
//@ cap(media)
|
||||
export function playlist() : Playlist { return undefined; }
|
||||
|
||||
//? Creates an invalid Playlists instance
|
||||
//@ cap(media)
|
||||
export function playlists() : Playlists { return undefined; }
|
||||
|
||||
//? Creates an invalid Location instance
|
||||
export function location() : Location_ { return undefined; }
|
||||
|
||||
|
|
121
lib/Media.ts
121
lib/Media.ts
|
@ -43,29 +43,6 @@ module TDev.RT {
|
|||
//@ [width].defl(480) [height].defl(800)
|
||||
export function create_picture(width:number, height:number) : Picture { return Picture.mk(width, height); }
|
||||
|
||||
//? Searches the Windows Phone Store (type in applications or music)
|
||||
//@ stub flow(SinkSafe) obsolete
|
||||
//@ [type].defl("music")
|
||||
export function search_marketplace(terms:string, type:string) : void
|
||||
{ }
|
||||
|
||||
export function askMusicAccessAsync(r : ResumeCtx): Promise { // boolean
|
||||
return r.rt.host.askSourceAccessAsync("music", "your songs, song albums and playlists.", false);
|
||||
}
|
||||
export function askPictureAccessAsync(r : ResumeCtx): Promise { // boolean
|
||||
return r.rt.host.askSourceAccessAsync("picture", "your pictures and picture albums.", false);
|
||||
}
|
||||
|
||||
//? Gets the playlists on the phone
|
||||
//@ cap(media) flow(SourceMusic) returns(Playlists)
|
||||
//@ embedsLink("Playlists", "Playlist") async
|
||||
export function playlists(r : ResumeCtx) // : Playlists
|
||||
{
|
||||
askMusicAccessAsync(r)
|
||||
.then(allow => r.resumeVal(undefined))
|
||||
.done();
|
||||
}
|
||||
|
||||
export function pictureUriForMedia(uri: string, media: string) {
|
||||
return uri;
|
||||
}
|
||||
|
@ -74,49 +51,6 @@ module TDev.RT {
|
|||
return Promise.as(undefined);
|
||||
}
|
||||
|
||||
var _pictureUrls: string[] = undefined;
|
||||
export function picturesAsync(uri : string) : Promise
|
||||
{
|
||||
if (!!_pictureUrls)
|
||||
return Promise.as(Pictures.mk(_pictureUrls));
|
||||
return BingServices.searchAsync("Images", "cat", null)
|
||||
.then((results) => {
|
||||
_pictureUrls = results.map((r) => r.url).slice(0, 4);
|
||||
return Pictures.mk(_pictureUrls);
|
||||
});
|
||||
}
|
||||
|
||||
var _pictureAlbums: PictureAlbums = undefined;
|
||||
export function pictureAlbumsAsync(uri : string) : Promise
|
||||
{
|
||||
if (_pictureAlbums) return Promise.as(_pictureAlbums);
|
||||
|
||||
return Media.picturesAsync(uri).then(pics => {
|
||||
_pictureAlbums = PictureAlbums.mk([PictureAlbum.mk('cats', 'cats', pics)]);
|
||||
return _pictureAlbums;
|
||||
});
|
||||
}
|
||||
|
||||
//? Gets the pictures on the phone
|
||||
//@ async cap(media) flow(SourcePicture) returns(Pictures)
|
||||
//@ embedsLink("Pictures", "Picture")
|
||||
export function pictures(r: ResumeCtx) {
|
||||
askPictureAccessAsync(r)
|
||||
.then(allow => {
|
||||
if (!allow) return Promise.as(Pictures.mk([]));
|
||||
else return Media.picturesAsync('');
|
||||
}).done(pics => r.resumeVal(pics));
|
||||
}
|
||||
|
||||
|
||||
//? Gets the saved pictures on the phone
|
||||
//@ cap(media) flow(SourcePicture) returns(Pictures)
|
||||
//@ embedsLink("Pictures", "Picture") async
|
||||
export function saved_pictures(r: ResumeCtx) // : Pictures
|
||||
{
|
||||
pictures(r);
|
||||
}
|
||||
|
||||
export function choosePictureAsync(title = 'choose a picture', description = ''): Promise {
|
||||
var cam = (<any>navigator).camera;
|
||||
if (cam) {
|
||||
|
@ -169,61 +103,6 @@ module TDev.RT {
|
|||
return choosePictureAsync().done(pic => r.resumeVal(pic));
|
||||
}
|
||||
|
||||
//? Gets the picture albums
|
||||
//@ cap(media) flow(SourcePicture) returns(PictureAlbums)
|
||||
//@ embedsLink("Picture Albums", "Picture Album") async
|
||||
export function picture_albums(r: ResumeCtx) //: PictureAlbums
|
||||
{
|
||||
askPictureAccessAsync(r)
|
||||
.then(allow => {
|
||||
if (!allow) return Promise.as(PictureAlbums.mk([]));
|
||||
else return Media.pictureAlbumsAsync('');
|
||||
}).done(albums => r.resumeVal(albums));
|
||||
}
|
||||
|
||||
export function initSongAlbumAsync(album: SongAlbum): Promise { // must call init
|
||||
album.init('', 0, null);
|
||||
return Promise.as(undefined);
|
||||
}
|
||||
|
||||
export function loadSongAlbumArtAsync(albumName: string): Promise { // string
|
||||
return Promise.as(undefined);
|
||||
}
|
||||
|
||||
export function songsAsync(album : string) : Promise // Songs
|
||||
{
|
||||
return Promise.as(Songs.mk([]));
|
||||
}
|
||||
|
||||
export function songAlbumsAsync() : Promise // SongAlbums
|
||||
{
|
||||
return Promise.as(SongAlbums.mk([]));
|
||||
}
|
||||
|
||||
//? Gets the songs on the phone
|
||||
//@ cap(media) flow(SourceMusic) returns(Songs)
|
||||
//@ embedsLink("Songs", "Song") async
|
||||
export function songs(r: ResumeCtx)
|
||||
{
|
||||
askMusicAccessAsync(r)
|
||||
.then(allow => {
|
||||
if (!allow) return Promise.as(Songs.mk([]));
|
||||
else return Media.songsAsync("");
|
||||
}).done(s => r.resumeVal(s));
|
||||
}
|
||||
|
||||
//? Gets the song albums on the phone
|
||||
//@ cap(media) flow(SourceMusic) returns(SongAlbums)
|
||||
//@ embedsLink("Song Albums", "Song Album") async
|
||||
export function song_albums(r : ResumeCtx) // : SongAlbums
|
||||
{
|
||||
askMusicAccessAsync(r)
|
||||
.then(allow => {
|
||||
if (!allow) return Promise.as(SongAlbums.mk([]));
|
||||
else return Media.songAlbumsAsync();
|
||||
}).done(s => r.resumeVal(s));
|
||||
}
|
||||
|
||||
//? Creates a new game board
|
||||
//@ timestamp
|
||||
//@ [result].writesMutable
|
||||
|
|
|
@ -1,57 +0,0 @@
|
|||
///<reference path='refs.ts'/>
|
||||
module TDev.RT {
|
||||
//? A picture album
|
||||
//@ stem("album") walltap cap(media)
|
||||
export class PictureAlbum
|
||||
extends RTValue
|
||||
{
|
||||
_name: string;
|
||||
_uri: string;
|
||||
_albums: PictureAlbums;
|
||||
_pictures: Pictures;
|
||||
|
||||
constructor() {
|
||||
super()
|
||||
}
|
||||
|
||||
static mk(name: string, uri : string, pictures : Pictures = null) {
|
||||
var pa = new PictureAlbum();
|
||||
pa._name = name;
|
||||
pa._uri = uri;
|
||||
pa._pictures = pictures;
|
||||
return pa;
|
||||
}
|
||||
|
||||
//? Gets the children albums
|
||||
//@ async embedsLink("Picture Album", "Picture Albums") returns(PictureAlbums)
|
||||
public albums(r : ResumeCtx) { //: PictureAlbums {
|
||||
if (this._albums) r.resumeVal(this._albums);
|
||||
|
||||
Media.pictureAlbumsAsync(this._uri)
|
||||
.done(albums => {
|
||||
this._albums = albums;
|
||||
r.resumeVal(this._albums)
|
||||
});
|
||||
}
|
||||
|
||||
//? Gets the name of the album
|
||||
public name(): string { return this._name; }
|
||||
|
||||
//? Gets the pictures
|
||||
//@ async embedsLink("Picture Album", "Pictures") returns(Pictures)
|
||||
public pictures(r : ResumeCtx) { //: Pictures {
|
||||
if (this._pictures) r.resumeVal(this._pictures);
|
||||
|
||||
Media.picturesAsync(this._uri).done(pics => {
|
||||
this._pictures = pics;
|
||||
r.resumeVal(this._pictures)
|
||||
});
|
||||
}
|
||||
|
||||
//? Displays the album to the wall
|
||||
public post_to_wall(s: IStackFrame): void {
|
||||
// TODO: display picture thumbnails
|
||||
s.rt.postText(this.name(), s.pc);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,36 +0,0 @@
|
|||
///<reference path='refs.ts'/>
|
||||
module TDev.RT {
|
||||
//? A collection of picture albums
|
||||
//@ stem("picalbums") enumerable cap(media)
|
||||
export class PictureAlbums
|
||||
extends RTValue
|
||||
{
|
||||
private a: PictureAlbum[] = [];
|
||||
|
||||
constructor() {
|
||||
super()
|
||||
}
|
||||
|
||||
static mk(albums: PictureAlbum[]): PictureAlbums {
|
||||
var pa = new PictureAlbums();
|
||||
pa.a = albums;
|
||||
return pa;
|
||||
}
|
||||
|
||||
//? Gets the item at position 'index'; invalid if index is out of bounds
|
||||
public at(index:number) : PictureAlbum { return this.a[Math.floor(index)]; }
|
||||
|
||||
//? Gets a random item; invalid if collection is empty
|
||||
public random(): PictureAlbum { return this.at(Math_.random(this.count())); }
|
||||
|
||||
//? Gets the number of elements in the collection
|
||||
public count(): number { return this.a.length; }
|
||||
|
||||
//? Displays the value to the wall
|
||||
public post_to_wall(s : IStackFrame): void {
|
||||
for (var i = this.a.length - 1; i >= 0; i--) {
|
||||
this.a[i].post_to_wall(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,81 +0,0 @@
|
|||
///<reference path='refs.ts'/>
|
||||
module TDev.RT {
|
||||
//? A collection of pictures
|
||||
//@ stem("pics") enumerable cap(media)
|
||||
export class Pictures
|
||||
extends RTValue
|
||||
{
|
||||
private _urls: string[] = [];
|
||||
constructor() {
|
||||
super()
|
||||
}
|
||||
|
||||
static mk(urls: string[]) {
|
||||
if (!urls) return undefined;
|
||||
|
||||
var pics = new Pictures();
|
||||
pics._urls = urls;
|
||||
return pics;
|
||||
}
|
||||
|
||||
//? Gets the picture at position 'index'; invalid if index is out of bounds
|
||||
//@ returns(Picture) picAsync
|
||||
public at(index: number, r : ResumeCtx) {
|
||||
this.atAsync(index, 'screen').done(p => r.resumeVal(p));
|
||||
}
|
||||
|
||||
public atAsync(index: number, media: string): Promise {
|
||||
index = Math.floor(index);
|
||||
if (index < 0 || index > this._urls.length)
|
||||
return Promise.as(undefined);
|
||||
|
||||
var url = Media.pictureUriForMedia(this._urls[index], media);
|
||||
return Picture.fromUrl(url);
|
||||
}
|
||||
|
||||
//? Gets a random picture; invalid if collection is empty
|
||||
//@ returns(Picture) picAsync
|
||||
public random(r : ResumeCtx) {
|
||||
this.at(Math_.random(this.count()), r);
|
||||
}
|
||||
|
||||
//? Gets the number of elements in the collection
|
||||
public count() : number {
|
||||
return this._urls.length;
|
||||
}
|
||||
|
||||
//? Finds a picture by name and returns the index. Returns -1 if not found.
|
||||
public find(name: string): number
|
||||
{
|
||||
for (var i = 0; i < length;++i)
|
||||
if (this._urls[i] === name)
|
||||
return i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
//? Displays the picture thumbmails to the wall
|
||||
public post_to_wall(s:IStackFrame) {
|
||||
this._urls.forEach((url) => {
|
||||
Link.mk(url, LinkKind.image).post_to_wall(s);
|
||||
});
|
||||
}
|
||||
|
||||
//? Gets the full resolution of i-th picture.
|
||||
//@ returns(Picture) picAsync
|
||||
public full(index: number, r : ResumeCtx) {
|
||||
this.atAsync(index, 'full').done(p => r.resumeVal(p));
|
||||
}
|
||||
|
||||
//? Gets the thumbnail of i-th picture.
|
||||
//@ returns(Picture) picAsync
|
||||
public thumbnail(index: number, r : ResumeCtx) {
|
||||
this.atAsync(index, 'thumbnail').done(p => r.resumeVal(p));
|
||||
}
|
||||
|
||||
//? Renamed to 'random'
|
||||
//@ hidden returns(Picture) picAsync
|
||||
public rand(r : ResumeCtx) {
|
||||
this.random(r);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -6,7 +6,6 @@ module TDev.RT {
|
|||
{
|
||||
var _rt: Runtime;
|
||||
var _activeSong: Song;
|
||||
var _songs: Songs = undefined;
|
||||
var _audio: HTMLAudioElement;
|
||||
var _source: HTMLSourceElement;
|
||||
var _shuffled: boolean;
|
||||
|
@ -17,7 +16,6 @@ module TDev.RT {
|
|||
{
|
||||
_rt = rt;
|
||||
_activeSong = null;
|
||||
_songs = null;
|
||||
_onActiveSongChanged = undefined;
|
||||
_onPlayerStateChanged = undefined;
|
||||
if (rt.eventEnabled("active song changed"))
|
||||
|
@ -32,7 +30,6 @@ module TDev.RT {
|
|||
Player.removePlayerStateChangedEvent();
|
||||
_rt = null;
|
||||
_activeSong = null;
|
||||
_songs = null;
|
||||
_onActiveSongChanged = undefined;
|
||||
_onPlayerStateChanged = undefined;
|
||||
}
|
||||
|
@ -101,14 +98,6 @@ module TDev.RT {
|
|||
_audio.onplaying = _audio.onpause;
|
||||
_audio.onended = () => {
|
||||
raisePlayerStateChanged();
|
||||
if (_songs) {
|
||||
if (_shuffled) {
|
||||
var i = (Math_.random(_songs.count() - 1) + 1);
|
||||
Player.playOne(_songs.at(i));
|
||||
}
|
||||
else
|
||||
Player.next();
|
||||
}
|
||||
};
|
||||
_source = <HTMLSourceElement>document.createElement("source");
|
||||
_audio.appendChild(_source);
|
||||
|
@ -116,34 +105,6 @@ module TDev.RT {
|
|||
}
|
||||
}
|
||||
|
||||
//? Moves to the next song in the queue of playing songs
|
||||
//@ cap(musicandsounds)
|
||||
//@ writesMutable
|
||||
export function next(): void
|
||||
{
|
||||
if (_songs) {
|
||||
var i = _songs.indexOf(_activeSong);
|
||||
i++;
|
||||
if (i < _songs.count()) {
|
||||
Player.playOne(_songs.at(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//? Moves to the previous song in the queue of playing songs
|
||||
//@ cap(musicandsounds)
|
||||
//@ writesMutable
|
||||
export function previous(): void
|
||||
{
|
||||
if (_songs) {
|
||||
var i = _songs.indexOf(_activeSong);
|
||||
i--;
|
||||
if (i > -1) {
|
||||
Player.playOne(_songs.at(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//? Pauses the currently playing song
|
||||
//@ cap(musicandsounds)
|
||||
//@ writesMutable
|
||||
|
@ -174,28 +135,9 @@ module TDev.RT {
|
|||
//@ writesMutable [song].readsMutable [song].writesMutable
|
||||
export function play(song: Song)
|
||||
{
|
||||
_songs = undefined; // clear song list
|
||||
Player.playOne(song);
|
||||
}
|
||||
|
||||
//? Plays a collection of songs
|
||||
//@ cap(musicandsounds)
|
||||
//@ writesMutable
|
||||
//@ embedsLink("Player", "Songs")
|
||||
export function play_many(songs: Songs): void
|
||||
{
|
||||
|
||||
if (songs.count() == 0) {
|
||||
_songs = undefined;
|
||||
Player.stop();
|
||||
}
|
||||
else {
|
||||
_songs = songs;
|
||||
_activeSong = undefined;
|
||||
Player.playOne(_songs.at(0));
|
||||
}
|
||||
}
|
||||
|
||||
//? Gets the position in seconds whithin the active song
|
||||
//@ returns(number)
|
||||
//@ readsMutable quickAsync
|
||||
|
|
|
@ -1,42 +0,0 @@
|
|||
///<reference path='refs.ts'/>
|
||||
module TDev { export module RT {
|
||||
//? A song playlist
|
||||
//@ walltap cap(media)
|
||||
export class Playlist
|
||||
extends RTValue
|
||||
{
|
||||
constructor() {
|
||||
super()
|
||||
}
|
||||
|
||||
//? Gets the duration in seconds
|
||||
//@ stub
|
||||
//@ readsMutable
|
||||
public duration() : number
|
||||
{ return undefined; }
|
||||
|
||||
//? Gets the name of the song
|
||||
//@ stub
|
||||
//@ readsMutable
|
||||
public name() : string
|
||||
{ return undefined; }
|
||||
|
||||
//? Gets the songs
|
||||
//@ stub
|
||||
//@ readsMutable
|
||||
public songs() : Songs
|
||||
{ return undefined; }
|
||||
|
||||
//? Displays the playlist to the wall
|
||||
//@ stub
|
||||
//@ readsMutable
|
||||
public post_to_wall() : void
|
||||
{ }
|
||||
|
||||
//? Plays the songs in the playlist
|
||||
//@ stub cap(musicandsounds)
|
||||
public play() : void
|
||||
{ }
|
||||
|
||||
}
|
||||
} }
|
|
@ -1,32 +0,0 @@
|
|||
///<reference path='refs.ts'/>
|
||||
module TDev { export module RT {
|
||||
//? A collection of playlists
|
||||
//@ enumerable cap(media)
|
||||
export class Playlists
|
||||
extends RTValue
|
||||
{
|
||||
constructor() {
|
||||
super()
|
||||
}
|
||||
// public jsonFields() => [];
|
||||
|
||||
//? Gets the number of playlists
|
||||
//@ stub
|
||||
//@ readsMutable
|
||||
public count() : number
|
||||
{ return undefined; }
|
||||
|
||||
//? Gets i-th playlist
|
||||
//@ stub
|
||||
//@ readsMutable
|
||||
public at(index:number) : Playlist
|
||||
{ return undefined; }
|
||||
|
||||
//? Displays the value to the wall
|
||||
//@ stub
|
||||
//@ readsMutable
|
||||
public post_to_wall() : void
|
||||
{ }
|
||||
|
||||
}
|
||||
} }
|
|
@ -1,10 +0,0 @@
|
|||
///<reference path='refs.ts'/>
|
||||
module TDev.RT {
|
||||
export module PrintManager
|
||||
{
|
||||
export var setPrintable = (isPrintable : boolean) =>
|
||||
{
|
||||
// overriden platform specific
|
||||
}
|
||||
}
|
||||
}
|
14
lib/Song.ts
14
lib/Song.ts
|
@ -7,7 +7,6 @@ module TDev.RT {
|
|||
{
|
||||
private _url: string = undefined;
|
||||
public /*protected*/ _path: string = undefined;
|
||||
private _album: SongAlbum = undefined;
|
||||
private _albumName: string = undefined;
|
||||
private _artist: string = undefined;
|
||||
private _duration: number = undefined;
|
||||
|
@ -56,20 +55,12 @@ module TDev.RT {
|
|||
this._name = name;
|
||||
this._albumName = albumName;
|
||||
this._artist = artist;
|
||||
this._album = SongAlbum.mk(this._albumName, this._artist);
|
||||
this._duration = duration;
|
||||
this._genre = genre;
|
||||
this._rating = rating;
|
||||
this._track = track;
|
||||
}
|
||||
|
||||
//? Gets the song album containing the song
|
||||
//@ returns(SongAlbum) cachedAsync
|
||||
public album(r: ResumeCtx) {
|
||||
if (this._initialized) r.resumeVal(this._album);
|
||||
else this.initAsync().done(() => r.resumeVal(this._album));
|
||||
}
|
||||
|
||||
//? Gets the name of the artist
|
||||
//@ returns(string) cachedAsync
|
||||
public artist(r: ResumeCtx) {
|
||||
|
@ -110,9 +101,6 @@ module TDev.RT {
|
|||
});
|
||||
}
|
||||
|
||||
// Gets a value whether the song is DRM protected
|
||||
//public @protected() : boolean{ return this._protected; }
|
||||
|
||||
//? Gets the users rating. -1 if not rated.
|
||||
//@ returns(number) cachedAsync
|
||||
public rating(r: ResumeCtx) {
|
||||
|
@ -164,8 +152,6 @@ module TDev.RT {
|
|||
this.initAsync().done(() => {
|
||||
if (this._artist)
|
||||
dc.appendChild(div("item-subtitle", this._artist));
|
||||
if (this._album)
|
||||
dc.appendChild(div("item-subtle", this._album.name()));
|
||||
d.appendChild(div('item-buttons', HTML.mkRoundButton("svg:play,currentColor", lf("play"), Ticks.songPlay, () => this.play())));
|
||||
});
|
||||
return d;
|
||||
|
|
161
lib/SongAlbum.ts
161
lib/SongAlbum.ts
|
@ -1,161 +0,0 @@
|
|||
///<reference path='refs.ts'/>
|
||||
module TDev.RT {
|
||||
//? A song album
|
||||
//@ stem("album") walltap cap(media)
|
||||
export class SongAlbum
|
||||
extends RTValue
|
||||
{
|
||||
private _name: string;
|
||||
private _artist: string;
|
||||
|
||||
private _genre: string = undefined;
|
||||
private _thumbnail: Picture;
|
||||
private _duration: number = 0;
|
||||
|
||||
private _songs: Songs;
|
||||
private _art: Picture;
|
||||
private _artInit = false;
|
||||
|
||||
constructor() {
|
||||
super()
|
||||
}
|
||||
|
||||
static mk(name: string, artist : string) : SongAlbum {
|
||||
var sa = new SongAlbum();
|
||||
sa._name = name;
|
||||
sa._artist = artist;
|
||||
return sa;
|
||||
}
|
||||
|
||||
public init(genre: string, duration: number, thumbnail : Picture) {
|
||||
this._genre = genre;
|
||||
this._duration = duration;
|
||||
this._thumbnail = thumbnail;
|
||||
}
|
||||
|
||||
public initArtAsync() : Promise {
|
||||
if(this._artInit)
|
||||
return Promise.as(undefined);
|
||||
return Media.loadSongAlbumArtAsync(this.name())
|
||||
.then(art => {
|
||||
this._artInit = true;
|
||||
this._art = art;
|
||||
});
|
||||
}
|
||||
|
||||
public initAsync(): Promise {
|
||||
if (this._genre != undefined)
|
||||
return Promise.as(undefined);
|
||||
return Media.initSongAlbumAsync(this);
|
||||
}
|
||||
|
||||
public initSongsAsync() : Promise { // Songs
|
||||
if (this._songs) return Promise.as(undefined);
|
||||
return Media.songsAsync(this._name)
|
||||
.then(s => this._songs = s);
|
||||
}
|
||||
|
||||
|
||||
public toString(): string {
|
||||
return this.name();
|
||||
}
|
||||
|
||||
//? Gets album art picture
|
||||
//@ returns(Picture) cachedAsync
|
||||
public art(r : ResumeCtx) //: Picture
|
||||
{
|
||||
this.initArtAsync().done(() => r.resumeVal(this._art));
|
||||
}
|
||||
|
||||
//? Gets the name of the artist
|
||||
public artist() : string
|
||||
{
|
||||
return this._artist || '';
|
||||
}
|
||||
|
||||
//? Gets the duration in seconds
|
||||
//@ returns(number) cachedAsync
|
||||
public duration(r : ResumeCtx) //: number
|
||||
{
|
||||
this.initAsync().done(() => r.resumeVal(this._duration || 0));
|
||||
}
|
||||
|
||||
//? Gets the genre of the song
|
||||
//@ returns(string) cachedAsync
|
||||
public genre(r : ResumeCtx) // : string
|
||||
{
|
||||
this.initAsync().done(() => r.resumeVal(this._genre || ''));
|
||||
}
|
||||
|
||||
//? Indicates if the album has art
|
||||
//@ returns(boolean) cachedAsync
|
||||
public has_art(r : ResumeCtx) //: boolean
|
||||
{
|
||||
this.initArtAsync().done(() => r.resumeVal(!!this._art));
|
||||
}
|
||||
|
||||
//? Gets the name of the album
|
||||
public name(): string { return this._name; }
|
||||
|
||||
public getViewCore(s: IStackFrame, b: BoxBase): HTMLElement {
|
||||
var d = div("item");
|
||||
var di = div("item-image contact-image");
|
||||
var dc = div("item-info item-with-button");
|
||||
d.setChildren([di, dc])
|
||||
if (this.name())
|
||||
dc.appendChild(div("item-title", this.name()));
|
||||
if (this.artist())
|
||||
dc.appendChild(div("item-subtitle", this.artist()));
|
||||
this.initAsync().done(() => {
|
||||
if (this._thumbnail) {
|
||||
var img = this._thumbnail.getImageElement();
|
||||
if (img) {
|
||||
img.className = "contact-image";
|
||||
di.appendChild(img);
|
||||
} else {
|
||||
this._thumbnail.initAsync().done(() => {
|
||||
var c = this._thumbnail.getViewCanvasClone();
|
||||
c.className = "contact-image";
|
||||
di.appendChild(c);
|
||||
});
|
||||
}
|
||||
}
|
||||
if (this._genre)
|
||||
dc.appendChild(div("item-subtle", this._genre));
|
||||
d.appendChild(div('item-buttons', HTML.mkRoundButton("svg:play,currentColor", lf("play"), Ticks.songAlbumPlay, () => this.playAsync().done())));
|
||||
})
|
||||
return d;
|
||||
}
|
||||
|
||||
//? Displays the song album on the wall
|
||||
public post_to_wall(s: IStackFrame): void { super.post_to_wall(s) }
|
||||
|
||||
//? Gets the songs
|
||||
//@ returns(Songs) async
|
||||
public songs(r : ResumeCtx) //: Songs
|
||||
{
|
||||
this.initSongsAsync()
|
||||
.done(() => r.resumeVal(this._songs))
|
||||
}
|
||||
|
||||
//? Gets the thumbnail picture
|
||||
//@ returns(Picture) cachedAsync
|
||||
public thumbnail(r : ResumeCtx) //: Picture
|
||||
{
|
||||
this.initAsync().done(() => r.resumeVal(this._thumbnail));
|
||||
}
|
||||
|
||||
public playAsync() {
|
||||
return this.initSongsAsync().then(() => {
|
||||
if (this._songs) Player.play_many(this._songs);
|
||||
});
|
||||
}
|
||||
|
||||
//? Plays the songs of the album
|
||||
//@ cap(musicandsounds) async
|
||||
public play(r : ResumeCtx): void {
|
||||
this.playAsync()
|
||||
.done(() => r.resume());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,36 +0,0 @@
|
|||
///<reference path='refs.ts'/>
|
||||
module TDev.RT {
|
||||
//? A collection of albums
|
||||
//@ stem("songalbums") enumerable cap(media)
|
||||
export class SongAlbums
|
||||
extends RTValue
|
||||
{
|
||||
private a: SongAlbum[] = [];
|
||||
constructor() {
|
||||
super()
|
||||
}
|
||||
|
||||
static mk(albums: SongAlbum[]) : SongAlbums {
|
||||
var r = new SongAlbums();
|
||||
r.a = albums;
|
||||
return r;
|
||||
}
|
||||
|
||||
//? Gets the item at position 'index'; invalid if index is out of bounds
|
||||
public at(index:number) : SongAlbum { return this.a[Math.floor(index)]; }
|
||||
|
||||
//? Gets a random item; invalid if collection is empty
|
||||
public random(): SongAlbum { return this.a.length == 0 ? undefined : this.at(Math_.random(this.a.length)); }
|
||||
|
||||
//? Gets the number of elements in the collection
|
||||
public count() : number
|
||||
{ return this.a.length; }
|
||||
|
||||
//? Displays the albums to the wall
|
||||
public post_to_wall(s : IStackFrame) : void
|
||||
{
|
||||
for (var i = this.a.length - 1; i > -1; --i)
|
||||
this.a[i].post_to_wall(s);
|
||||
}
|
||||
}
|
||||
}
|
74
lib/Songs.ts
74
lib/Songs.ts
|
@ -1,74 +0,0 @@
|
|||
///<reference path='refs.ts'/>
|
||||
module TDev.RT {
|
||||
//? A collection of songs
|
||||
//@ immutable enumerable cap(media)
|
||||
export class Songs
|
||||
extends RTValue
|
||||
{
|
||||
private _songs: Song[] = [];
|
||||
|
||||
constructor() {
|
||||
super()
|
||||
}
|
||||
|
||||
static mk(songs: Song[])
|
||||
{
|
||||
var s = new Songs();
|
||||
s._songs = songs;
|
||||
return s;
|
||||
}
|
||||
|
||||
//? Gets the item at position 'index'; invalid if index is out of bounds
|
||||
public at(index: number): Song
|
||||
{
|
||||
return this._songs[index];
|
||||
}
|
||||
|
||||
public indexOf(song: Song): number
|
||||
{
|
||||
if (!song) return -1;
|
||||
|
||||
var url = song.url();
|
||||
for (var i = 0; i < this._songs.length; ++i) {
|
||||
if (this._songs[i].url() === url)
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
//? Gets a random item; invalid if collection is empty
|
||||
public random() : Song
|
||||
{
|
||||
if (this._songs.length == 0) return undefined;
|
||||
return this._songs[Math_.random(this._songs.length)];
|
||||
}
|
||||
|
||||
//? Gets the number of elements in the collection
|
||||
public count(): number
|
||||
{
|
||||
return this._songs.length;
|
||||
}
|
||||
|
||||
//? Plays the song.
|
||||
//@ cap(musicandsounds)
|
||||
public play()
|
||||
{
|
||||
Player.play_many(this);
|
||||
}
|
||||
|
||||
//? Displays the songs on the wall
|
||||
public post_to_wall(s: IStackFrame)
|
||||
{
|
||||
for (var i = this._songs.length - 1; i >= 0; --i) {
|
||||
this._songs[i].post_to_wall(s);
|
||||
}
|
||||
}
|
||||
|
||||
//? Renamed to 'random'
|
||||
//@ hidden
|
||||
public rand() : Song
|
||||
{
|
||||
return this.random();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -43,20 +43,12 @@
|
|||
///<reference path='PageButtonManager.ts'/>
|
||||
///<reference path='Phone.ts'/>
|
||||
///<reference path='Picture.ts'/>
|
||||
///<reference path='PictureAlbum.ts'/>
|
||||
///<reference path='PictureAlbums.ts'/>
|
||||
///<reference path='Pictures.ts'/>
|
||||
///<reference path='Place.ts'/>
|
||||
///<reference path='Player.ts'/>
|
||||
///<reference path='Playlist.ts'/>
|
||||
///<reference path='Playlists.ts'/>
|
||||
///<reference path='Radio.ts'/>
|
||||
///<reference path='Senses.ts'/>
|
||||
///<reference path='Social.ts'/>
|
||||
///<reference path='Song.ts'/>
|
||||
///<reference path='SongAlbum.ts'/>
|
||||
///<reference path='SongAlbums.ts'/>
|
||||
///<reference path='Songs.ts'/>
|
||||
///<reference path='Sound.ts'/>
|
||||
///<reference path='Spring.ts'/>
|
||||
///<reference path='Sprite.ts'/>
|
||||
|
@ -78,7 +70,6 @@
|
|||
///<reference path='XmlObject.ts'/>
|
||||
///<reference path='ShakeDetector.ts'/>
|
||||
///<reference path='ShareManager.ts'/>
|
||||
///<reference path='PrintManager.ts'/>
|
||||
///<reference path='JsonParser.ts'/>
|
||||
///<reference path='UserMediaManager.ts'/>
|
||||
///<reference path='CanvasChart.ts'/>
|
||||
|
|
Загрузка…
Ссылка в новой задаче