forked from Jackarain/avplayer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
101 lines (87 loc) · 2.14 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#define __STDC_CONSTANT_MACROS
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <SDL/SDL.h>
#include <X11/Xlib.h>
#include <boost/filesystem.hpp>
namespace fs = boost::filesystem;
#include <avplay.h>
#include "player.h"
int main ( int argc, char *argv[] )
{
// 判断播放参数是否足够.
if ( argc != 2 )
{
printf ( "usage: avplayer <video>\n" );
return -1;
}
player ply;
XInitThreads();
SDL_Init ( SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_EVENTTHREAD );
// 判断打开的媒体类型,
// 根据媒体文件类型选择不同的方式打开.
std::string filename ( argv[1] );
if ( fs::path ( filename ).extension() == ".torrent" )
{
if ( ply.open ( filename.c_str(), MEDIA_TYPE_BT ) < 0 )
return -1;
}
else
{
std::string is_url = filename.substr ( 0, 7 );
if ( is_url == "http://" )
{
if ( ply.open ( filename.c_str(), MEDIA_TYPE_HTTP ) < 0 )
return -1;
}
else if ( is_url == "rtsp://" )
{
// if (!ply.open(filename.c_str(), MEDIA_TYPE_RTSP))
return -1;
}
else
{
if ( ply.open ( filename.c_str(), MEDIA_TYPE_FILE ) < 0 )
return -1;
}
}
// 开始播放
ply.play();
SDL_WM_SetCaption ( ( std::string ( "正在播放" ) + filename ).c_str(),
"" );
while ( true )
{
int w=-1, h=-1;
SDL_Event event;
SDL_WaitEvent ( &event );
if ( event.type == SDL_QUIT )
{
// ply.stop();
break;
}
if ( event.type == SDL_KEYDOWN )
{
switch (event.key.keysym.sym)
{
case SDLK_RIGHT:
ply.fwd();
break;
case SDLK_LEFT:
ply.bwd();
break;
case SDLK_f:
ply.togglefs();
break;
case SDLK_q:
return 0;
}
}
if ( event.type == SDL_VIDEORESIZE){
SDL_SetVideoMode(event.resize.w,event.resize.h,32,SDL_RESIZABLE);
ply.resize(event.resize.w,event.resize.h);
}
}
// ply.wait_for_completion();
return 0;
}